akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
import random
import time
import copy
from operator import itemgetter
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]


CI=sorted([(v,i) for i,v in enumerate(C)],key=itemgetter(0),reverse=True)
CHO=[i for v,i in CI[:5]]

CHOICES=[[0]]
for i in range(1,D+1):
    SI=sorted([(v,i) for i,v in enumerate(S[i])],key=itemgetter(0),reverse=True)
    CHOICES.append([i for v,i in SI[:5]])
    
ANS=0
T=[0]
LAST=[0]*27
for day in range(1,D+1):
    SCORE=[-1<<30]*27
    for j in range(1,27):
        SC=0
        SC+=S[day][j]

        for k in range(1,27):
            if j==k:
                continue
            SC-=C[k]*(day-LAST[k])
        SCORE[j]=SC

    choose=SCORE.index(max(SCORE))
    T.append(choose)
    LAST[choose]=day

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

MAX=ANS
MAXT=copy.deepcopy(T)
d=0
after_t=0

while time.time()-time0<1.8:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.choice(CHO+CHOICES[d])

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS*10000<MAX*9998:
        T=BT
        LAST=BLAST
        ANS=BANS
    elif ANS>MAX:
        MAX=ANS
        MAXT=copy.deepcopy(T)

print(*MAXT[1:])


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

int main(){
    int n;cin>>n;
    int max=9;
    int count=0;
    for(int i=1;i<=6;i++){
        if(i%2==1&&max<n){
            count+=((i==1)?max:9*(int)pow(10,i-1));
        }
        if(max>=n){
            if(i%2==1) count+=((i==1)?n:n-(int)pow(10,i-1)+1);
            break;
        }
      max=max*10+9;
    }

    cout<<count<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(ll i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();

int main()
{
    fast();
    ll a,b;
    cin>>a>>b;
    vi v;
    ll res=1e18;
    for(ll i=a;i<=min(a+2019,b);i++)
        v.pb(i);
    for(int i=0;i<v.size();i++){
        for(int j=i+1;j<v.size();j++)
            res=min(res,(v[i]*v[j])%2019);
    }
    cout<<res;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int h[200005];

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	sort(h, h + n, greater<int>());
	long long ans = 0LL;
	for (int i = k; i < n; i++)
	{
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  const int64_t money_start = 1000000000000000, inf = 1L << 62;
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--; t--;
  vector<vector<pair<int, int>>> yen(n), snuuk(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    yen.at(u).emplace_back(v, a);
    yen.at(v).emplace_back(u, a);
    snuuk.at(u).emplace_back(v, b);
    snuuk.at(v).emplace_back(u, b);
  }
  vector<int64_t> d_yen(n, inf), d_snuuk(n, inf), d_total(n);
  {
    priority_queue<pair<int64_t, int>> q;
    q.emplace(0, s);
    while (!q.empty()) {
      auto p = q.top();
      q.pop();
      int64_t d = -p.first;
      int u = p.second;
      if (d_yen.at(u) < inf) continue;
      d_yen.at(u) = d;
      for (auto next : yen.at(u)) {
        int v = next.first, fair = next.second;
        q.emplace(-(d + fair), v);
      }
    }
  }
  {
    priority_queue<pair<int64_t, int>> q;
    q.emplace(0, t);
    while (!q.empty()) {
      auto p = q.top();
      q.pop();
      int64_t d = -p.first;
      int u = p.second;
      if (d_snuuk.at(u) < inf) continue;
      d_snuuk.at(u) = d;
      for (auto next : snuuk.at(u)) {
        int v = next.first, fair = next.second;
        q.emplace(-(d + fair), v);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    d_total.at(i) = d_yen.at(i) + d_snuuk.at(i);
  }
  for (int i = n - 2; i >= 0; i--) {
    d_total.at(i) = min(d_total.at(i), d_total.at(i + 1));
  }
  for (int i = 0; i < n; i++) {
    cout << money_start - d_total.at(i) << "\n";
  }
}


Measured memory_bytes: 16356
n, a, b = map(int, input().split())
cnt = 0
def total(x):
    total = 0
    X = str(x)
    for s in X:
        total += int(s)
    return total

for x in range(1, n + 1):
    if a <= total(x) <= b:
        cnt += x

print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
int d1[4][4] = { {-1,-1,0,0},{0,0,1,1},{0,0,1,1},{-1,-1,0,0} };
int d2[4][4] = { {0,1,1,0},{0,1,1,0},{-1,0,0,-1},{-1,0,0,-1} };
int main() {
	int n; map<P, int>mp;
	cin >> n;
	pair<P,int> p[100000];
	rep(i, n) {
		int x, y, w;
		cin >> x >> y >> w;
		mp[{x, y}] = w;
		p[i] = { { x,y },w };
	}
	int ma = 0;
	rep(i, n) {
		int nx = p[i].first.first; int ny = p[i].first.second;
		rep(j, 4) {
			int sum = 0;
			rep(k, 4) {
				int newx = nx + d1[j][k]; int newy = ny + d2[j][k];
				sum += mp[{newx, newy}];
			}
			ma = max(ma, sum);
		}
	}
	cout << ma << " / 1" << endl;
	return 0;
}


Measured memory_bytes: 60524
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;

struct UnionFind {
    vector<int> node;
    UnionFind(int n) {
        node = vector<int>(n, -1);
    }
    int find(int x) {
        return node[x] < 0 ? x : node[x] = find(node[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        node[x] += node[y];
        node[y] = x;
        return true;
    }
    int size(int x) {
        return -node[find(x)];
    }
};

struct Edge {
    int from, to, cost;
    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
};

int main() {
    int N, M, K; scanf("%d%d%d", &N, &M, &K);
    vector<int> col(N);
    int num_unknown = 0;
    for(int i=0; i<N; i++) scanf("%d", &col[i]), num_unknown += (!col[i]);

    vector<Edge> edges;
    for(int i=0; i<M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        u--; v--;
        edges.push_back(Edge{u, v, w});
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N+K);

    long long int ans = 0, rest = K-1;
    for(int i=0; rest>0 && i<M; i++) {
        int u = edges[i].from, v = edges[i].to;
        int id_u = col[u] ? col[u] - 1 : K+u;
        int id_v = col[v] ? col[v] - 1 : K+v;
        if(uf.unite(id_u, id_v)) {
            ans += edges[i].cost;
            rest--;
        }
    }
    if(rest) printf("-1\n");
    else printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(void) {
	string str;
	cin >> str;
	int now = 0;
	int len = str.length();
	vector<int> h(len);
	for (int i = 0; i < len; ++i) {
		if (str[i] == '\\') {
			--now;
		}
		else if (str[i] == '/') {
			++now;
		}
		h[i] = now;
	}

	vector<int> a(len);
	a[len-1] = h[len-1];
	for (int i = 1; i < len; ++i) {
		a[len-i-1] = max(a[len-i],h[len-i-1]);
	}

	int nop = 0;
	int sum = 0;
	int ind = 0;
	queue<int> q;
	bool end = false;
	while (!end) {
		if (str[ind] == '\\') {
			int hs = h[ind]+1;
			if (hs <= a[ind]) {
				int na = 0;
				bool find = false;
				for (int i = ind; !find && i < len; ++i) {
					na += hs - h[i];
					if (str[i] == '\\') {
						--na;
					}
					else if (str[i] == '/') {
						++na;
						if (hs == h[i]) {
							find = true;
						}
					}
					++ind;
				}
				++nop;
				sum += na;
				q.push(na);
				--ind;
			}
		}
		++ind;
		if (ind >= len) {
			end = true;
		}
	}
	cout << sum << endl;
	cout << nop;
	while (!q.empty()) {
		cout << " " << q.front();
		q.pop();
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,m,d;
    cin >> n >> m >> d;
    if ( d == 0){
        cout << fixed <<  setprecision(20) << (m-1)/(double)n << endl;
    } else {
        cout << fixed << setprecision(10) << ((double)2*(m - 1)*(n - d))/(double)(n*n) << endl;
    }
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n;
	n=s.length();
	char ch=s[n-1];
	if(ch=='s')
	{
		cout<<s+"es";
	}
	else
	{
		cout<<s+"s";
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    ll h;
    ll w;
    ll k;

    cin >> h >> w >> k;

    char pt[h][w];
    rep(i, h) rep(j, w) cin >> pt[i][j];

    // rep(i, h) {
    //     rep(j, w) cout << pt[i][j] << " ";
    //     cout << endl;
    // }
    int sum = 0;
    rep(i, 1 << w + h) {
        // cout << i << endl;
        char copyPt[h][w];
        rep(a, h) rep(b, w) copyPt[a][b] = pt[a][b];

        int cur = i;
        for (int j = 0; j < w + h; j++) {
            int fract = cur % 2;
            cur = cur / 2;

            if (fract == 1) {
                if (j < w) {
                    rep(k, h) { copyPt[k][j] = '.'; }
                } else {
                    rep(k, w) { copyPt[j - w][k] = '.'; }
                }
            }
        }

        int cnt = 0;
        rep(a, h) rep(b, w) if (copyPt[a][b] == '#') cnt++;

        if (cnt == k) {
            sum++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    vp vec(m);
    REP(i,m){
        cin>>vec[i].fi>>vec[i].se;
        vec[i].fi--;
        vec[i].se--;
    }
    int ans=0;
    REP(i,m){
        UnionFind uf(n);
        REP(j,m){
            if(i!=j){
                uf.unite(vec[j].fi,vec[j].se);
            }
        }
        if(uf.size(0)!=n){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(2):
        if a[i+j] > b[i]:
            cnt += b[i]
            a[i+j] -= b[i]
            b[i] = 0
        else:
            cnt += a[i+j]
            b[i] -= a[i+j]
            a[i+j] = 0
print(cnt)

Measured memory_bytes: 18476
q_text = str(input())
q_num = int(input())

for i in range(q_num):
  q = input()
  if q.startswith("print"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    print(q_text[a:b+1])
    
  elif q.startswith("reverse"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    temp_text=q_text[a:b+1]
    q_text = q_text[:a] + temp_text[::-1] + q_text[b+1:]
    #print(q_text)
  
  elif q.startswith("replace"):
    command,a,b,p = q.split()
    a=int(a)
    b=int(b)
    q_text = q_text[:a] + p + q_text[b+1:]
    #print(q_text)


Measured memory_bytes: 5616
/* #region template */
#![allow(unused_imports)]
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let x: f64 = io.r();
    let mut m = 100.0f64;
    for y in 1.. {
        m = (m * 1.01).floor();
        if m >= x {
            io.w(y);
            return;
        }
    }
}


Measured memory_bytes: 2704
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

vector<vector<pair<int,int> > > G(100010);
vector<int> ans(100010, -1);

void dfs(int now, int parent, int color){
  
  ans[now] = color;
  
  for(auto nw: G[now]){
    int n = nw.first, w = nw.second;
    if(n == parent) continue;
    if(w%2==0) dfs(n,now,color);
    else dfs(n,now,color^1);
  }
  
}

int main(){
  int N, u, v, w;
  cin >> N;
  rep(i,N-1){
    cin >> u >> v >> w;
    G[u].push_back(make_pair(v,w));
    G[v].push_back(make_pair(u,w));
  }
  dfs(1,-1,0);
  for(int i=1; i<=N; i++)
    cout << ans[i] << endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int X, A, B;

    cin >> X >> A >> B;

    int num = (X - A) / B;

    cout << X - A - num * B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

signed main(void)
{
  long long int n, m, ans = 0;
  scanf("%lld %lld", &n, &m);
  if (n <= m / 2) {
    ans = n;
    m -= n * 2;
    n = 0;
  } 
  else {
    ans = m / 2;
    n -= m / 2;
    m = 0;
  }
  printf("%lld\n", ans + m / 4);

  return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;
int main() {
 int N,D;
 cin>>N>>D;
 int K=2*D+1;
 cout<<(N+K-1)/K<<endl;
 return 0;}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var x = Number(lines[0]);
 var a = 100;
 var year = 0;
 while(true){
   if(a >= x){
     break;
   }
   a = Math.floor(a * 1.01);
   year++;
 }

 console.log(year);
});

Measured memory_bytes: 30172
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(c-a)>2*d){
    P("No");
  }else if(b<=a && a<c && (c-a)>d){
    P("No");
  }else if(a<c && c<=b && (c-a)>d){
    P("No");
  }else if(b<=c && c<a && (a-c)>d){
    P("No");
  }else if(c<a && a<=b && (a-c)>d){
    P("No");
  }else if(a<b && b<c && (c-b>d || b-a>d)){
    P("No");
  }else if(c<b && b<a && (a-b>d || b-c>d)){
    P("No");
  }else{
    P("Yes");
  }
  return 0;
}


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

using Point = pair<int, int>;

const int INF = 1e6 + 1;
int H, W;
vector<vector<int>> height, way;

vector<Point> next(int y, int x) {return {{y-1, x}, {y+1, x}, {y, x-1}, {y, x+1}};}

bool bottom(int y, int x) {
  for(auto p: next(y, x)) if(height[p.first][p.second] < height[y][x]) return false;
  return true;
}

void mark(int sy, int sx) {
  queue<Point> q;
  q.emplace(sy, sx);
  vector<vector<bool>> visited(H+2, vector<bool>(W+2, false));
  while(!q.empty()) {
    int y, x;
    tie(y, x) = q.front();
    q.pop();
    if(height[y][x] == INF) continue;
    if(visited[y][x]) continue;
    visited[y][x] = true;
    if(2 <= way[y][x]) continue;
    ++way[y][x];
    for(auto p: next(y, x)) if(height[y][x] < height[p.first][p.second]) if(!visited[p.first][p.second]) q.emplace(p.first, p.second);
  }
}

int main() {
  cin >> H >> W;
  height.assign(H+2, vector<int>(W+2, INF));
  for(auto i = 1; i <= H; ++i) for(auto j = 1; j <= W; ++j) cin >> height[i][j];

  way.assign(H+2, vector<int>(W+2, 0));
  for(auto i = 1; i <= H; ++i) for(auto j = 1; j <= W; ++j) if(bottom(i, j)) {
    mark(i, j);
  }

  auto ans = 0;
  for(auto i = 1; i <= H; ++i) for(auto j = 1; j <= W; ++j) if(2 <= way[i][j]) ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n ,a ,sum=0;
    cin>>a>>n;
    ll arr[n];
    for(int i = 0; i<n ;i++)
    {
        cin>>arr[i];
        sum = sum + arr[i];
    }
	if(sum>=a)
	{
	    cout<<"Yes";
	} else{
	    cout<<"No";
	}

	return 0;
}

Measured memory_bytes: 4420
#include <stdio.h>

int main (void) {
  int H, W, i, j;
  H = 1; W = 1;
  while (H != 0 || W != 0){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0) return 0;
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
	if (i == 0 || i == H-1 || j == 0 || j == W-1)printf("#");
	else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
}



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

int main() {
  int a;
  cin>>a;
  bool b=a/100<=12 && a/100>=1;
  bool c=a%100<=12 && a%100>=1;
  if(b&&c) cout<<"AMBIGUOUS";
  if(b&&!c) cout<<"MMYY";
  if(!b&&c) cout<<"YYMM";
  if(!b&&!c) cout<<"NA";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
int n,m,M,tot,ans[maxn],b[maxn];
pair<int,int> a[maxn];
int head[maxn],nxt[maxn*2],to[maxn*2],id[maxn*2];
bool vis[maxn];
void add(int x,int y,int I) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y; id[tot]=I;
}
void dfs(int u) {
	vis[u]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (vis[v]) continue;
		dfs(v);
		if (b[v]) b[v]^=1,b[u]^=1,ans[++tot]=id[i];
	}
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n); read(M);
	for (int i=1;i<=n;i++)
		read(a[i].first),read(a[i].second);
	sort(a+1,a+n+1);
	a[n+1]=make_pair((1e9)+1,0);
//	for (int i=1;i<=n;i++) printf("%d ",a[i].second); printf("\n");
	for (int i=1;i<=n+1;i++) b[i]=a[i].second^a[i-1].second;
//	for (int i=1;i<=n+1;i++) printf("%d ",b[i]); printf("\n");
	int x,y,l,r;
	for (int i=1;i<=M;i++) {
		read(x); read(y);
		l=n+1,r=0;
		for (int j=1;j<=n;j++)
			if (x<=a[j].first&&a[j].first<=y) l=min(l,j),r=max(r,j);
		x=lower_bound(a+1,a+n+2,make_pair(x,-1))-a;
		y=upper_bound(a+1,a+n+2,make_pair(y,100))-a-1;
		if (x<=y) {
			add(x,y+1,i);
			add(y+1,x,i);
	//		printf("%d %d %d %d %d\n",x,y+1,l,r,i);
		}
	}
	tot=0;
	for (int i=1;i<=n+1;i++)
		if (!vis[i]) {
			dfs(i);
			if (b[i]) { printf("-1\n"); return 0; }
		}
	sort(ans+1,ans+tot+1);
	printf("%d\n",tot);
	for (int i=1;i<=tot;i++) printf("%d ",ans[i]); printf("\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 10624
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int a[200001];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=n;i>1;i-=2)printf("%d ",a[i]);
	printf("%d ",a[1]);
	for(int i=(n-1)%2+2;i<n;i+=2)printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long
string jg(string  x) {
    int f = 0;
    rep(i, x.size()) {
        f += stoi(x.substr(i,1));
    }
    int xx = stoi(x.substr(0, x.size()));
    if (xx%f == 0)return "Yes";
    else return "No";
}
int main() {
    string n;
    cin >> n;
    cout << jg(n) << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, C;
    cin >> A >> B >> C;

    ll ans = 0;

    map<ll, ll> mp;

    mp[A]++;
    mp[B]++;
    mp[C]++;

    if(mp.size() == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    // if(ans){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
r = set(list(range(n)))
N = n*(n-1) // 2 + 1
for _ in range(N):
    if not r:
        print(_)
        break
    ne = set()
    flag = True
    for j in r:
        if not a[j]:
            continue
        c = a[j][0]
        if c == "-":
            continue
        if j + 1 == a[c-1][0]:
            a[j][0] = "-"
            a[c-1][0] = "-"
            ne.add(j)
            ne.add(c-1)
    for j in list(ne):
        if a[j]:
            if a[j][0] == "-":
                a[j].pop(0)
                flag = False
                if not a[j]:
                    ne.remove(j)
    if flag:
        print(-1)
        break
    else:
        r = ne


Measured memory_bytes: 35072
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    string t;cin >> t;
    cout << t + s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL P(N);
	for (LL n = 0; n < N; n++) {
		cin >> P[n];
		P[n]--;
	}
	VLL pos(N);
	for (LL n = 0; n < N; n++) {
		pos[P[n]] = n;
	}
	LL ans = 0;
	LL p = N-1;
	for (LL n = 0; n < N; n++) {
		if (p == -1)break;
		if (pos[n] <= p) {
			ans++;
			p = pos[n] - 1;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  string ans = "";
  rep(i, s.size()) ans += 'x';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#define M 100
using namespace std;
int main(void)
{
	int n,i,j,k,a[41],b[41],c[41],d[41],m,min,kaku,cnt,F[100],ex;
	int x,y,x2,y2;
	int date[41][41];
	int cost[41],flg[41],cost1[41];
	
	scanf("%d",&n);
	scanf("%d",&m);
	
	for(i=1;i<=m;i++) {
		scanf("%d,%d,%d,%d",&a[i],&b[i],&c[i],&d[i]);//?????????
	}
	
	scanf("%d,%d,%d,%d",&x,&y,&x2,&y2);//?????????
	
	for(i=1;i<=n;i++) {
		cost[i]=M;
		flg[i]=0;
	}
	
	
	for(i=1;i<=n;i++) {
		for(j=1;j<=n;j++) {
			date[i][j]=M;
		}
	}
	
	for(i=1;i<=m;i++) {
		date[a[i]][b[i]]=c[i];
		date[b[i]][a[i]]=d[i];
	}
	
	for(i=1;i<=n;i++) date[i][i]=0;
	
	cost[x]=0;
	for(i=1;i<=n;i++) {
		min=M;
		for(j=1;j<=n;j++) F[i]=0;
		for(j=1;j<=n;j++) {
			if(flg[j]==0 && cost[j]<min) {
				kaku=j;
				min=cost[j];
			}
		}
		
		flg[kaku]=1;
		
		for(j=1;j<=n;j++) {
			if((cost[kaku]+date[kaku][j])<cost[j]) cost[j]=cost[kaku]+date[kaku][j];
		}
		
	}
//	for(i=1;i<=n;i++) printf("%d<-%d - %d\n",x,i,cost[i]);
	
//	printf("\n");
	//??°??????
	for(i=1;i<=n;i++) {
		cost1[i]=M;
		flg[i]=0;
	}
	for(i=1;i<=n;i++) {
		for(j=1;j<=n;j++) {
			date[i][j]=M;
		}
	}
	
	for(i=1;i<=m;i++) {
		date[a[i]][b[i]]=c[i];
		date[b[i]][a[i]]=d[i];
	}
	
	for(i=1;i<=n;i++) date[i][i]=0;
	
	cost1[y]=0;
	for(i=1;i<=n;i++) {
		min=M;
		for(j=1;j<=n;j++) F[i]=0;
		for(j=1;j<=n;j++) {
			if(flg[j]==0 && cost1[j]<min) {
				kaku=j;
				min=cost1[j];
			}
		}
		
		flg[kaku]=1;
		
		for(j=1;j<=n;j++) {
			if((cost1[kaku]+date[kaku][j])<cost1[j]) cost1[j]=cost1[kaku]+date[kaku][j];
		}
	}
//	for(i=1;i<=n;i++) printf("%d<-%d - %d\n",y,i,cost1[i]);
	/**/
/*	printf("       ");
	for(i=1;i<=n;i++) printf("%4d ",i);
	printf("\n");
	printf("\n");
	for(i=1;i<=n;i++) {
		printf("%4d   ",i);
		for(j=1;j<=n;j++) {
			printf("%4d ",date[i][j]);
		}
		printf("\n");
	}*/
	/**/
	x2=x2-y2-cost[y]-cost1[x];
	printf("%d\n",x2);
	return 0;
}
	
	
	

Measured memory_bytes: 1036
#include <stdio.h>
int main(void) {
    char grid[52][52];
    int h, w, i, j, cnt=0;
    scanf("%d %d", &h, &w);
    for(i=1; i<=h; i++)
      	scanf("%s", &grid[i]);
    
  	for(i=1; i<=h; i++) {
        for(j=1; j<=w; j++) {
            if(grid[i][j]=='#') {
                if(grid[i][j]!=grid[i][j-1] && grid[i][j]!=grid[i-1][j] && grid[i][j]!=grid[i][j+1] && grid[i][j]!=grid[i+1][j])
                    cnt++;
            }
        }
    }
    if(cnt>0)
        printf("No");
    else
        printf("Yes");
    return 0;
}

Measured memory_bytes: 128
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	// 入力
	int N, K;
	cin >> N >> K;

	int ans = 1;
	REP(i, N) {
		if (ans < K) {
			ans *= 2;
		} else {
			ans += K;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
l=[1]*n
red=set([0])
for i in a:
    l[i[0]-1]-=1
    l[i[1]-1]+=1
    if i[0]-1 in red:
        red.add(i[1]-1)
        if l[i[0]-1]==0:red.remove(i[0]-1)
print(len(red))

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

int main() { 
    int a,b,c,d,e,k;
    int at[5];
    for(int i=0; i<5; i++) {
        int p; cin >> p;
        at[i] = p;
    }
    cin >> k;
    bool ok = true;
    for (int i=0; i<4; i++) {
        for (int j=i; j<5; j++) {
            if (at[j] - at[i] > k) {
                ok = false;
                break;
            }

        }
    }

    if(ok) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
Ai = [list(map(int, input().split())) for _ in range(M)]

Ai.sort(key=lambda x: x[1])

count = 0
left = 0
for a in Ai:
    if a[0] >= left:
        left = a[1]
        count += 1
print(count)

Measured memory_bytes: 29084
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(void){
    int n,m,h;
    vector<int> v,vv;
    int a,b;
    int count=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>h;
        v.push_back(h);
        vv.push_back(1);
    }
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(v[a-1]<v[b-1])vv[a-1]=0;
        else if(v[a-1]>v[b-1])vv[b-1]=0;
        else if(v[a-1]==v[b-1]){vv[a-1]=0;vv[b-1]=0;}
    }
    for(int i=0;i<n;i++){
        if(vv[i]==1)count++;
    }
    cout<<count;
}

Measured memory_bytes: 4316
class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # グループのサイズ
        return -self.parents[self.find(x)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xysort = [None] * n
for x, y in xy:
    xysort[x - 1] = y - 1

# 解説AC
uf = Unionfind(n)
tmp, yfrag = 0, [0] * n
for x, y in enumerate(xysort[:n - 1], 1):
    yfrag[y] = 1
    tmp += yfrag[n - x] + (y > n - x)
    if tmp < x:
        uf.union(x, x - 1)

for x, y in xy:
    print(uf.size(x - 1))


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

int main()
{
  long long h,w,m; scanf("%lld%lld%lld", &h, &w, &m);
  long long row[h], col[w];
  map<pair<long long, long long>, long long> mp;
  for(int i=0; i<h; ++i) row[i]=0ll;
  for(int i=0; i<w; ++i) col[i]=0ll;
  for(int i=0; i<m; ++i){
    long long x, y; scanf("%lld%lld", &x, &y);
    --x;
    --y;
    mp[{x,y}]++;
    row[x]++;
    col[y]++;
  }
  vector<pair<long long, long long>> vr, vc;
  for(int i=0; i<h; ++i) vr.push_back({row[i], i});
  for(int j=0; j<w; ++j) vc.push_back({col[j], j});
  sort(vr.begin(), vr.end());
  sort(vc.begin(), vc.end());
  reverse(vr.begin(), vr.end());
  reverse(vc.begin(), vc.end());
  long long ans=0;
  int counter=0;
  for(int i=0; i<vr.size(); ++i){
    int ok=0;
    for(int j=0; j<vc.size(); ++j){
      long long val=vr[i].first + vc[j].first;
      if(mp[{vr[i].second, vc[j].second}]) val-=1;
      ++counter;
      ans=max(ans, val);
      if(counter==1e6+16+1e6) ok=1;
      if(ok) break;
    }
    if(ok) break;
  }
  counter=0;
  for(int i=0; i<vc.size(); ++i){
    int ok=0;
    for(int j=0; j<vr.size(); ++j){
      long long val=vr[j].first + vc[i].first;
      if(mp[{vr[j].second, vc[i].second}]) val-=1;
      ++counter;
      ans=max(ans, val);
      if(counter==1e6+16+1e6) ok=1;
      if(ok) break;
    }
    if(ok) break;
  }

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

Measured memory_bytes: 286016
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
string test[345678];
signed main() {
	int n, k, a = 1; string s; char mi = 'z'; cin >> n >> k >> s;
	for (int h = 0; h < n; h++) { mi = min(mi, s[h]); }
	if (s[n - 1] == mi) { a = 2; }
	for (int h = 2; h <= min(k, (long long)15); h++) {
		a *= 2;
		if (a >= n) { 
			for (int i = 0; i < n; i++) { cout << mi; } cout << endl; return 0;
		}
	}
	string r = s;
	for (int h = 0; h < k; h++) {
		string t = r; reverse(r.begin(), r.end()); t += r;
		for (int i = 0; i < n + 5; i++) { test[i] = ""; }
		if (h == k - 1) {
			for (int i = 0; i <= n; i++) {
				for (int j = i; j < i + n; j++) {
					test[i] += t[j];
				}
			}
			sort(test, test + n + 1); 
			cout << test[0] << endl; return 0;
		}
		else {
			reverse(t.begin(), t.end());
			for (int i = 0; i <= n; i++) {
				for (int j = i; j < i + n; j++) {
					test[i] += t[j];
				}
			}
			sort(test, test + n + 1); r = test[0];
			reverse(r.begin(), r.end());
		}
	}
	return 0;
}

Measured memory_bytes: 42752
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1

vector<vector<ll>> cache;
ll knapsack(int cur, int used, int W, const vector<ll>& wt,
            const vector<ll>& val) {
  if (cur == wt.size()) {
    return 0;
  }
  if (cache[cur][used] != -1) {
    return cache[cur][used];
  }
  // don't consider this item
  ll option1 = knapsack(cur + 1, used, W, wt, val);
  // consider this item
  ll option2 = 0;
  if (used + wt[cur] <= W) {
    option2 = knapsack(cur + 1, used + wt[cur], W, wt, val) + val[cur];
  }
  return cache[cur][used] = max(option1, option2);
}
void solve() {
  int n, w;
  cin >> n >> w;
  vector<ll> wt(n), val(n);
  for (int i = 0; i < n; ++i) {
    cin >> wt[i] >> val[i];
  }
  cache.assign(n, vector<ll>(w + 1, -1));
  cout << knapsack(0, 0, w, wt, val) << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 79488
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
        int w = sc.nextInt();
        String s[] = new String[h];
        for(int i = 0; i < h; i++){
        	s[i] = sc.next();
        }
        int ans[][] = new int[h][w]; 
        for(int i = 0; i < h; i++){
        	for(int j = 0; j < w; j++){
            	if(s[i].substring(j, j + 1).equals(".")){
                	ans[i][j] = 0;
                }else{
                    ans[i][j] = -1;
                }
            }
        }
        for(int i = 0; i < h; i++){
        	for(int j = 0; j < w; j++){
            	if(ans[i][j] != -1){
                    //左上の値
                	if(i != 0 && j != 0 && ans[i - 1][j - 1] == -1){
                    	ans[i][j]++;
                    }
                    //上の値
                    if(i != 0 && ans[i - 1][j] == -1){
                    	ans[i][j]++;
                    
                    }
                    //右上の値
                    if(i != 0 && j != w - 1 && ans[i - 1][j + 1] == -1){
                    	ans[i][j]++;
                    }
                    //左の値
                    if(j != 0 && ans[i][j - 1] == -1){
                    	ans[i][j]++;
                    }
                    //右の値
                    if(j != w - 1 && ans[i][j + 1] == -1){
                    	ans[i][j]++;
                    }
                    //左下の値
                    if(i != h - 1 && j != 0 && ans[i + 1][j - 1] == -1){
                    	ans[i][j]++;
                    }
                    //下の値
                    if(i != h - 1 && ans[i + 1][j] == -1){
                    	ans[i][j]++;
                    }
                    //右下の値
                    if(i != h - 1 && j != w - 1 && ans[i + 1][j + 1] == -1){
                    	ans[i][j]++;
                    }
                }
            }
        }
        for(int i = 0; i < h; i++){
        	for(int j = 0; j < w; j++){
            	if(ans[i][j] == -1){
                	System.out.print("#");
                }else{
                	System.out.print(ans[i][j]);
                }
            }
            System.out.println();
        }
    }
} 

Measured memory_bytes: 36336
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, W;
int A[101], B[101];
ll dp[100001][101];

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> W;
    repp(i, 1, N+1) cin >> A[i] >> B[i];
    repp(i, 1, N+1) rep(j, W+1) {
        dp[j][i] = max(dp[j][i-1], A[i]<=j?dp[j-A[i]][i-1]+B[i]:0);
    }

    ll ret = 0;
    rep(i, W+1) get_max(ret, dp[i][N]);

    cout << ret << endl;
}

Measured memory_bytes: 79232
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z,k;
	int s, ans;
	scanf("%d %d %d %d", &x, &y,&z,&s);
	ans = 0;
	f(i, 3010) {
		f(j, 3010) {
			k = s;
			k -= (i * x);
			k -= (j*y);
			if (k >= 0) {
				if (k%z == 0)ans++;
			}
		}
	}

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


	return 0;
}

Measured memory_bytes: 128
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        k: usize,
        v: [[usize];k]
    }

    //println!("{:?} {} {}", v, n, k);

    let mut set: HashSet<usize> = HashSet::new();

    for a in &v {
        for i in 0..a.len() {
            set.insert(a[i]);
        }
    }

    //println!("{:?}", set);

    let mut ans = 0;
    for i in 0..n {
        let result = set.get(&(i + 1));
        if result == None {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2292