akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

struct xydata {
    int x; int y;
};

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

int h, w;
vector< vector<char> > smap(110, vector<char>(110, '.'));

void bfs(vector< vector<char> > &xmap, char key, int xx, int yy) {
    queue<xydata> que;
    xydata indata; indata.x = xx; indata.y = yy;
    que.push(indata);
    xmap.at(yy).at(xx) = 'X';
    while(!que.empty()) {
        xydata now = que.front(); que.pop();
        for(int i = 0; i < 4; ++i) {
            int nx = now.x+dx[i]; int ny = now.y+dy[i];
            if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                if(xmap.at(ny).at(nx) == key) {
                    xmap.at(ny).at(nx) = 'X';
                    xydata next; next.x = nx; next.y = ny;
                    que.push(next);
                }
            }
        }
    }
}

int main() {
    while(1) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> smap.at(i).at(j);
            }
        }

        int cnt = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                if(smap.at(i).at(j) != 'X') {
                    cnt++;
                    bfs(smap, smap.at(i).at(j), j, i);
                }
            }
        }

        cout << cnt << endl;
    }
}


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

int a,b;

int main()
{
	cin>>a>>b;
	if(a>0 && a<10)
	{
		if(b>0 && b<10)
		{
			cout<<a*b<<'\n';
			return 0;
		}
	}
	cout<<"-1\n";
	return 0;
}

Measured memory_bytes: 256
n = input()

if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
    print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
else:
    print("bon")


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

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

int H, W;
bool fid[510][510];
bool mem[510][510];
int cnt;

signed main()
{
    cin >> H >> W;

    rep(i, H)rep(j, W)
    {
        int a;
        cin >> a;
        fid[i][j] = a & 1;
        mem[i][j] = a & 1;
    }

    rep(i, H)rep(j, W - 1)
    {
        if(mem[i][j])
        {
            cnt++;
            mem[i][j + 1] ^= true;
        }
    }

    rep(i, H - 1)
    {
        if(mem[i][W - 1])
        {
            cnt++;
            mem[i + 1][W - 1] ^= true;
        }
    }

    cout << cnt << endl;

    rep(i, H)rep(j, W - 1)
    {
        if(fid[i][j])
        {
            cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
            fid[i][j + 1] ^= true;
        }
    }

    rep(i, H - 1)
    {
        if(fid[i][W - 1])
        {
            cout << i + 1 << " " << W << " " << i + 2 << " " << W << endl;
            fid[i + 1][W - 1] ^= true;
        }
    }

    return 0;
}

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

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

struct mypair {
    int A;
    int B;
};

int main() {
    int N, H, W;
    cin >> N >> H >> W;
    vector<struct mypair> Pair(N);

    for (int i = 0; i < N; i++)
        cin >> Pair.at(i).A >> Pair.at(i).B;
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (Pair.at(i).A >= H && Pair.at(i).B >= W) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 40, inf = 0x3f3f3f3f;
int n, m, s = 1, e, cnt[nsz + 5], w[nsz + 5], ans = inf;
vector<int> g[nsz + 5];

void dfs(int u = s, int p = s, int res = w[s]) {
    ++cnt[u];
    for (int v : g[u]) {
        if (!cnt[v]) {
            res += w[v];
        }
        ++cnt[v];
    }
    if (u == e) {
        ans = min(ans, res);
    } else {
        for (int v : g[u]) {
            if (cnt[v] > 1)  continue;
            dfs(v, u, res);
        }
    }
    --cnt[u];
    for (int v : g[u]) {
        --cnt[v];
        if (!cnt[v]) {
            res -= w[v];
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    e = n;
    cont (u, n) {
        cin >> w[u];
    }
    cont (i, m) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs();
    cout << ans << endl;
}



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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int A, B;

int main(){
    cin >> A >> B;

    cout << (A-2*B > 0 ? A-2*B : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
const ll MOD = 1000000007;

int b[105], ans[105], ansidx = 0;
int main(){
    //input
    int n;
    scanf("%d", &n);
    int idx[105] = {0};
    rep(i, n) scanf("%d", b+n-1-i);

    //solve
    int ng = 0;
    rep(i ,n){
        if(b[n-1-i] > i+1) ng = 1;
        
    }
    if(ng) {
        puts("-1");
        return 0;
    }
    rep(i, n){
        int j = i;
        for(;j < n; j++){
            if(b[j] == n-j) break;
        }
        ans[i] = b[j];
        for(int k = j; k > 0; k--){
            b[k] = b[k-1];
        }
    }

    //output
    rep(i, n) printf("%d\n", ans[n-1-i]);
}

Measured memory_bytes: 1728
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    mochi_count = int(input())
    mochi_diameters = [int(input()) for _ in range(mochi_count)]

    step_count = len(set(mochi_diameters))
    print(step_count)

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


void solve()
{

 int A,B,sum,cur,x;
 int the=0;

cin>>A>>B;
x=A-(B*2);

if(A>B && x>=the)
{
    cout<<x;

}else{

    puts("0");

}

}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+100;
ll par[maxn],rankn[maxn];
void init(ll V){
    for(ll i=0;i<V;i++){
        par[i]=i;
        rankn[i]=0;
    }
}
ll find(ll x){
    if(x==par[x]){
        return x;
    }else 
        return par[x]=find(par[x]); 
}
void unite(ll x,ll y){
    x=find(x);
    y=find(y);
    if(x==y){
        return;
    }
    if(rankn[x]>rankn[y]){
        par[y]=x;
    }else{
        par[x]=y;
        if(rankn[y]==rankn[x]){
            rankn[y]++;
        }
    }
}
ll n,m;
int main(){
    ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    init(n+10);
    ll p1,p2;
    for(int i=1;i<=m;i++){
        cin>>p1>>p2;
        //cout<<p1<<' '<<p2<<endl;
        unite(p1,p2);
    }
    map<ll,ll> mp;
    ll ans=-2;
    for(int i=1;i<=n;i++){
        ll far=find(i);
        //cout<<far<<endl;
        mp[far]++;
        ans=max(ans,mp[far]);
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define INF 2<<29

typedef long long ll;

int main(){
  int n,k;
  scanf("%d %d",&n,&k);
  if(k==1) printf("0\n");
  else printf("%d\n",n-k);
  
  return 0;
}



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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N,K;

  cin>>N>>K;

  long long ans=K;
  
  for(int i=1;i<N;i++){
    ans*=(K-1);
  }

  cout<<ans<<endl;
  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define test() ll t;cin>>t;while(t--)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define test() ll t;cin>>t;while(t--)
int main()
{
	ll n,b;
	cin>>n>>b;
	ll ans=0;
	while(n/b!=0)
	{
		n=n/b;
		ans++;
	}
	cout<<ans+1;
	
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn exp(n :usize) -> usize{
    let mut sum = 1;
    let div = 1000000007;
    for _i in 0..n {
	sum *= 2;
	if sum >= div{
	    sum -= div;
	}
    }
    sum
}

//main function
fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = Vec::with_capacity(n);
    let mut sub: Vec<i32> = Vec::with_capacity(n);
    unsafe{
	a.set_len(n);
	sub.set_len(n);
    }
    // initialize
    for i in 0..n{
	a[i as usize] = 0;
	if n%2==0{
	    if i%2==0 {
		sub[i as usize] = 0;
	    }else{
		sub[i as usize] = 2;
	    }
	}else{
	    if i==0{
		sub[i as usize] = 1;
	    }else if i%2==0 {
		sub[i as usize] = 2;
	    }else{
		sub[i as usize] = 0;
	    }
	}
    }

    for _i in 0..n{
	let number: usize = read();
	a[number]+=1;
    }
    
    for i in 0..n{
	if a[i as usize] != sub[i as usize] {
	    println!("0");
	    return;
	}
    }
    println!("{}",exp(n/2));
}


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

//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;

#define int long long
#define pb push_back
#define rep(i,a,b) for ( int i = a; i < b; i++)
#define all(c) (c).begin(),(c).end()

using namespace std;

signed main()
{
   int x;
   cin>>x;
   int val;
   int ans1 =0;
   int ans2 =0;
   for(int i=-1000; i<1000; i++ ){
   	val = pow(i,5);
   	for(int j=-1000; j<1000; j++){
   		int val1 = pow(j,5);
   		if(val-val1==x){
   			ans1 = i;
   			ans2 =j;
   			break;
		   }
	   }
   }
   cout<<ans1<<" "<<ans2;
   
   
}
        
        
    

    





Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
long long cnt[100100],sum,a,b,c;
int n,q;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	while(n--){
		cin>>a;
		cnt[a]++;
		sum+=a;
	}
	cin>>q;
	while(q--){
		cin>>b>>c;
		sum-=b*cnt[b];
		sum+=c*cnt[b];
		cnt[c]+=cnt[b];
		cnt[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 4392
from collections import Counter


n = int(input())
A = list(map(int, input().split()))

counts = Counter(A)

total = 0
for num, count in counts.items():
    pattern = count * (count - 1) // 2
    total += pattern

for a in A:
    count = counts[a]
    if count == 1:
        print(total)
        continue
    prev = count * (count - 1) // 2
    after = (count - 1) * (count - 2) // 2
    delta = prev - after
    print(total - delta)

Measured memory_bytes: 26780
#include <iostream>
#include <cmath>
#include <iomanip>
#include <assert.h>
#include <string>
#include <algorithm>

using namespace std;
class dice{
	int a[7];
public:	
	dice(){ for (int i = 1; i <= 6; ++i) a[i] = i + 1; }
	void set(int i, int n){ assert(1<=i && i<=6); a[i] = n; }
	void rot(char ch){
		assert(ch=='W' || ch=='N' || ch=='S' || ch=='E');
		int tmp = a[1];
		switch (ch)
		{
		case 'W':
			a[1] = a[3]; a[3] = a[6]; a[6] = a[4]; a[4] = tmp;
			break;
		case 'E':
			a[1] = a[4]; a[4] = a[6]; a[6] = a[3]; a[3] = tmp;
			break;
		case 'N':
			a[1] = a[2]; a[2] = a[6]; a[6] = a[5]; a[5] = tmp;
			break;
		case 'S':
			a[1] = a[5]; a[5] = a[6]; a[6] = a[2]; a[2] = tmp;
			break;
		}
	}
	int top(){ return a[1]; }
	int south(){ return a[2]; }
	int west(){ return a[4]; }
	int east(){ return a[3]; }
	int north(){ return a[5]; }
	int bottom(){ return a[6]; }
	friend bool operator==(dice d1, dice d2){	
		for (int k = 0; k < 4; ++k){
			for (int i = 0; i < 4; ++i){
				for (int j = 0; j < 4; ++j){
					if (d1.top() == d2.top() &&
						d1.south() == d2.south() &&
						d1.north() == d2.north() &&
						d1.east() == d2.east() &&
						d1.west() == d2.west() &&
						d1.bottom() == d2.bottom()
						) return true;
					d1.rot('W');
				}
				d1.rot('N');
			}
			d1.rot('W');
		}
		return false;
	}
};

int main(){
	dice D1,D2;
	int a[6], b[6];
	for (int i = 0; i < 6; ++i){ cin >> a[i]; D1.set(i + 1, a[i]); }
	for (int i = 0; i < 6; ++i){ cin >> b[i]; D2.set(i + 1, b[i]); }
	if (D1==D2) cout << "Yes\n"; else cout << "No\n";
}

Measured memory_bytes: 1128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;

vector<int> bfs(const vector<vector<int>> &G, int start) {
  vector<int> dist(G.size(), -1);
  queue<int> q;
  q.push(start);
  dist[start] = 0;
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u: G[v]) {
      if (dist[u] == -1) {
        dist[u] = dist[v] + 1;
        q.push(u);
      }
    }
  }
  return dist;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> fdist = bfs(G, 0);
  vector<int> sdist = bfs(G, N - 1);
  int fennec = 0, snuke = 0;
  for (int v = 0; v < N; v++) {
    if (fdist[v] <= sdist[v]) {
      ++fennec;
    } else {
      ++snuke;
    }
  }
  cout << (fennec > snuke ? "Fennec" : "Snuke") << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> ab(n, vector<int>(n, 0));
    REP(i, m){
        int a,b;
        cin >> a >> b;a--;b--;
        ab[a][b] = 1;
        ab[b][a] = 1;
    }

    vector<int> p(n);
    iota(ALL(p), 0);
    int ans = 0;
    do{
        if(p[0]!=0)continue;
        bool flag = true;
        REP(i, n-1){
            if(!ab[p[i]][p[i+1]]){
                flag = false;
                break;
            }
        }
        if(flag)ans++;
    }while(next_permutation(ALL(p)));
    pr(ans);
}

Measured memory_bytes: 256
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  for i in xrange(N):
    ct = 0  # Current Time
    for cs in xrange(i, N-1):
      #print '*' * 20, 'DEPART', cs, ct
      c, s, f = CSF[cs]
      if ct < s:
        ct = s
      elif ct % f:
        ct += f - ct % f
      ct += c
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)

main()

Measured memory_bytes: 33896
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;
struct edge
{
    int to;
    ll a, b;
    edge(int to, ll a, ll b) : to(to), a(a), b(b) {}
};

ll calc(ll t, ll a, ll b)
{
    return t + (b - 1) / (a + t) + 1;
}

ll rt(const ll n)
{
    ll inf = 1, sup = 2 * std::sqrt(n);
    while (sup - inf > 1) {
        const ll mid = (sup + inf) / 2;
        if (mid * mid == n) { return mid; }
        (mid * mid > n ? sup : inf) = mid;
    }
    return inf;
}

ll ternary_seartch(ll t, ll a, ll b)
{
    //cout << "t,a,b = " << (ll)t << " " << a << " " << b << endl;
    // ll ok = t, ng = INF;
    // if ((ll)b <= a + t) return calc(t, a, b);
    // while (ng - ok > 2) {
    //     //cout << "ng, ok = " << (ll)ng << " " << (ll)ok << endl;
    //     ll d = (ng - ok) / 3, l = ok + d, r = ng - d;
    //     if (calc(l, a, b) <= calc(r, a, b))
    //         ng = r;
    //     else
    //         ok = l;
    // }
    // return min(min(calc(ok, a, b), calc(ng, a, b)), calc(ok + 1, a, b));
    const ll c = rt(b);
    if (c * c == b) {
        const ll o = c - a;
        if (o >= t) {
            return 2 * c - a;
        } else {
            return calc(t, a, b);
        }
    } else {
        if (t >= c - a + 1) {
            return calc(t, a, b);
        } else {
            return std::min(calc(c - a, a, b), calc(c - a + 1, a, b));
        }
    }
}

ll dijkstra(vector<vector<edge>>& G, int s, int t)
{
    int N = G.size();
    vector<ll> ret(N, INF);
    priority_queue<pair<ll, int>> wait;
    wait.emplace(0, s);
    while (!wait.empty()) {
        ll t = -wait.top().first;
        int v = wait.top().second;
        wait.pop();
        if (t > ret[v]) continue;
        ret.at(v) = t;
        for (size_t i = 0; i < G[v].size(); ++i) {
            edge e = G[v][i];
            ll a = e.a, b = e.b;
            int v_ = e.to;
            ll t_ = ternary_seartch(t, a, b);
            if (t_ < ret.at(v_)) {
                ret.at(v_) = t_;
                wait.emplace(-t_, v_);
            }
        }
    }
    return ret[t];
}

int main()
{
    int N, M, S, G;
    cin >> N >> M >> S >> G;
    --S;
    --G;
    vector<vector<edge>> H(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        H[u].push_back(edge{v, a, b});
        H[v].push_back(edge{u, a, b});
    }
    ll ans = dijkstra(H, S, G);
    if (ans == INF)
        cout << -1 << endl;
    else
        cout << (ll)ans << endl;
    return 0;
}



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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if( a < b ){
    if( b < c ){cout<<a<<" "<<b<<" "<<c<<endl;}
    else{
      if( a < c ){cout<<a<<" "<<c<<" "<<b<<endl;}
      else{cout<<c<<" "<<a<<" "<<b<<endl;}
    }
  }
  else{
    if( a < c ){cout<<b<<" "<<a<<" "<<c<<endl;}
    else{
      if( b < c ){cout<<b<<" "<<c<<" "<<a<<endl;}
      else{cout<<c<<" "<<b<<" "<<a<<endl;}
    }
  }
}



Measured memory_bytes: 3092
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 200010
char ch[Maxn];
int main(){
    long long Ans=0;
    scanf("%s",ch+1);
    n=strlen(ch+1);
    int sum=0;
    for(register int i=1;i<=n;++i)
        if(ch[i]=='B')sum++;
        else Ans+=sum;
    printf("%lld\n",Ans);
    return 0;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1 << 30;


int L, X[200000];
int64 dp[200002][5];

int64 rec(int idx, int flag) {
  if(idx == L) return 0;
  if(~dp[idx][flag]) return dp[idx][flag];
  int64 ret = INF;
  if(flag == 0) {
    ret = min(ret, rec(idx + 1, 0) + X[idx]);
    ret = min(ret, rec(idx, 1));
  } else if(flag == 1) { // 偶数
    ret = min(ret, rec(idx + 1, 1) + (X[idx] == 0 ? 2 : X[idx] % 2));
    ret = min(ret, rec(idx, 2));
  } else if(flag == 2) { // 奇数
    ret = min(ret, rec(idx + 1, 2) + 1 - X[idx] % 2);
    ret = min(ret, rec(idx, 3));
  } else if(flag == 3) {
    ret = min(ret, rec(idx + 1, 3) + (X[idx] == 0 ? 2 : X[idx] % 2));
    ret = min(ret, rec(idx, 4));
  } else {
    ret = min(ret, rec(idx + 1, 4) + X[idx]);
  }
  return dp[idx][flag] = ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> L;
  for(int i = 0; i < L; i++) {
    cin >> X[i];
  }
  cout << rec(0, 0) << endl;
}





Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 300;
int dp[5 + nmax][5 + nmax];
int comb[5 + nmax][5 + nmax];
int sum[5 + nmax][5 + nmax];
int modulo;

void computecomb() {
  for(int i = 0;i <= nmax; i++) {
    comb[i][0] = 1;
    for(int j = 1;j <= i; j++) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; 
      if(modulo <= comb[i][j])
        comb[i][j] -= modulo;
    }
  }
}

int main() {
  int n, k;
  std::cin >> n >> k >> modulo;
  computecomb();
  for(int i = 0;i <= k; i++)
    dp[0][i] = dp[1][i] = 1;
  sum[1][0] = dp[1][0];
  for(int i = 1;i <= k; i++)
    sum[1][i] = (sum[1][i - 1] + dp[1][i]) % modulo;

  for(int i = 2;i <= n + 1; i++) {
    for(int j = 1; j <= k; j++) {
      for(int i2 = 1; i2 < i; i2++) {
        dp[i][j] += 1LL * sum[i2][j - 1] * dp[i - i2][j] % modulo * comb[i - 2][i2 - 1] % modulo;
        if(modulo <= dp[i][j])
          dp[i][j] -= modulo;
      }
      sum[i][j] = sum[i][j - 1] + dp[i][j];
      if(modulo <= sum[i][j])
        sum[i][j] -= modulo;
    }
  }
  std::cout << dp[n + 1][k];
  return 0;
}


Measured memory_bytes: 4628
import java.util.Scanner;

public class Main {
    int             p, q, a, n, c;
    private Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        Main m = new Main();
        m.run();
    }

    public void run() {
        while (true) {
            p = scanner.nextInt();
            q = scanner.nextInt();
            a = scanner.nextInt();
            n = scanner.nextInt();
            if (p == 0 && q == 0 && a == 0 && n == 0) {
                break;
            }
            c = 0;
            dfs(0, 1, 1, 0);
            System.out.println(c);
        }
    }

    public void dfs(int num, int den, int x, int k) {
        if (p * den == q * num) {
            c++;
            return;
        }
        if (k == n)
            return;
        if (p * den < q * num)
            return;
        for (int i = x; i * den <= a; i++) {
            int nn = num * i + den;
            int nd = i * den;
            dfs(nn, nd, i, k + 1);
        }
    }
}

Measured memory_bytes: 23604
//copyright TheStaticMind reis guzel kod yaziyosun valla her sey net anlasiliyor.

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define ii pair<int,int>
#define fre freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
vector <int> deg(100005,0);
vector <int> color(100005,-1);
vector <int> adj[100005];
map <ii,int> edge;
void dfs(int x,int pre){
	int ban=-1;
	if(pre!=0)ban=color[edge[{pre,x}]];
	int c=1;
	for(int i=0;i<adj[x].size();i++){
		int y=adj[x][i];
		if(y==pre)continue;
		if(ban==c)c++;
		color[edge[{x,y}]]=c++;
		dfs(y,x);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//fre
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		deg[a]++;
		deg[b]++;
		edge[{a,b}]=i;
		edge[{b,a}]=i;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int G=*max_element(deg.begin(),deg.end());
	cout<<G<<'\n';
	dfs(1,0);
	for(int i=0;i<n-1;i++){
		cout<<color[i]<<'\n';
	}
}


Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n,x;
	int sum_popa=0, sum_papu=0;
	vector <int> num;
	cin >> n;
	for (int i =0;i<n;i++){
		cin >>x;
		num.push_back(x);
	}
	sort (num.begin(), num.begin()+n);
	bool par = true;
	for (int i=n-1; i>=0; i--){
		if (par) sum_popa += num[i];
		else sum_papu += num[i];
		
		if (par) par = false;
		else par = true;
	}
	
	cout << fabs(sum_papu - sum_popa);
	
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n, t;
    cin >> n >> t;
    int ans = 1001;
    for(int i = 0; i < n; i++){
        int c, ti;
        cin >> c >> ti;
        if(ti <= t){
            ans = min(ans, c);
        }
    }
    if(ans == 1001){
        cout << "TLE\n";
        return 0;
    }
    cout << ans << "\n";
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 1262; ++i) {
		if (floor(0.08 * i) == a && floor(0.1 * i) == b) {
			cout << i << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> x, y, h;
    vector<ll> ox, oy;
    for(int i=0;i<n;i++){
        ll tx, ty, th; cin >> tx >> ty >> th;
        if(th == 0){
            ox.push_back(tx);
            oy.push_back(ty);
        }else{
            x.push_back(tx); y.push_back(ty); h.push_back(th);
        }
    }
    ll in_size = x.size();
    ll out_size = ox.size();
    for(ll cx=0;cx<=100;cx++){
        for(ll cy=0;cy<=100;cy++){
            bool pos = true;
            ll predh = abs(x[0] - cx) + abs(y[0] - cy) + h[0];
            for(ll i=1;i<in_size;i++){
                ll p = abs(x[i] - cx) + abs(y[i] - cy) + h[i];
                if(p != predh){
                    pos = false;
                    break;
                }
            }
            for(ll i=0;i<out_size;i++){
                if(predh - abs(ox[i] - cx) - abs(oy[i] - cy) > 0){
                    pos = false;
                    break;
                }
            }
            if(pos){
                cout << cx << " " << cy << " " << predh << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>

using namespace std;

vector<int> solve_dp(
	int max_damage, const vector<int> &mp, const vector<int> &damage)
{
	vector<int> dp(max_damage, -1);
	dp[0] = 0;
	for(int i = 0; i < mp.size(); ++i){
		for(int j = 0; j < max_damage; ++j){
			if(dp[j] < 0){ continue; }
			int idx = j + damage[i];
			if(idx >= max_damage){ break; }
			if(dp[idx] < 0){
				dp[idx] = dp[j] + mp[i];
			}else{
				dp[idx] = min(dp[idx], dp[j] + mp[i]);
			}
		}
	}
	for(int i = max_damage - 2; i >= 0; --i){
		if(dp[i + 1] < 0){ continue; }
		if(dp[i] < 0){
			dp[i] = dp[i + 1];
		}else{
			dp[i] = min(dp[i], dp[i + 1]);
		}
	}
	return dp;
}

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<int> hp(n);
		int max_hp = 0;
		for(int i = 0; i < n; ++i){
			cin >> hp[i];
			max_hp = max(max_hp, hp[i]);
		}
		int m;
		cin >> m;
		vector<int> all_mp, all_damage;
		vector<int> single_mp, single_damage;
		int max_damage = 0;
		for(int i = 0; i < m; ++i){
			string name, target;
			int mp, damage;
			cin >> name >> mp >> target >> damage;
			max_damage = max(max_damage, damage);
			if(damage == 0){ continue; }
			if(target == "All"){
				all_mp.push_back(mp);
				all_damage.push_back(damage);
			}else{
				single_mp.push_back(mp);
				single_damage.push_back(damage);
			}
		}
		int am = all_mp.size(), sm = single_mp.size();
		max_damage = max(max_damage, max_hp) + max_damage + 1;
		vector<int> all_dp = solve_dp(max_damage, all_mp, all_damage);
		vector<int> single_dp = solve_dp(max_damage, single_mp, single_damage);
		int answer = INT_MAX;
		for(int i = 0; i < max_damage; ++i){
			if(all_dp[i] < 0){ continue; }
			int sum = all_dp[i];
			for(int j = 0; j < n; ++j){
				if(hp[j] <= i){ continue; }
				if(single_mp.size() == 0 && hp[j] > i){
					sum = INT_MAX;
					break;
				}
				sum += single_dp[hp[j] - i];
			}
			answer = min(answer, sum);
		}
		cout << answer << endl;
	}
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	
	int seki = a*b;
	
	if(seki%2==0){
		cout << "Even";
	}else {
		cout << "Odd";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define meme(a, b) memset(a, b, sizeof(a))

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}
void flaged(bool flag){
    if(flag) cout << "Yes\n";
    else cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf(){
    fact[0] = finv[0] = 1;
    for(ll i = 1; i < maxa; i++){fact[i] = (fact[i-1]*i) %MOD;finv[i] = (finv[i-1]*power(i))%MOD;}
}
// nCr
ll ncr(ll N, ll R){ if(R > N) return 0; return (fact[N]*((finv[R]*finv[N-R])%MOD))%MOD;}

void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll f = 0;
    if(a == b && b == c) f  =  1;
    if(a!= b && a!= c && b != c) f = 1;
    flaged(1-f);

}

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


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

typedef vector <int> VI;
typedef vector <VI> VVI;

int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		VVI students( n, VI( n ) );
		for ( int i = 0; i < n; i++ ) for ( int j = 0; j < n; j++ ) cin >> students[i][j];

		VVI tallests( n, VI( n, 0 ) );
		VVI shortests( n, VI( n, 0 ) );

		// get shortest
		for ( int i = 0; i < n; i++ )
		{
			int shortest;
			int shortest_col;
			for ( int j = 0; j < n; j++ )
			{
				if ( j == 0 || shortest > students[i][j] )
				{
					shortest = students[i][j];
					shortest_col = j;
				}
			}
			for ( int j = 0; j < n; j++ )
			{
				if ( shortest == students[i][j] ) shortests[i][j] = 1;
			}
		}

		// get tallest
		for ( int i = 0; i < n; i++ )
		{
			int tallest;
			int tallest_row;
			for ( int j = 0; j < n; j++ )
			{
				if ( j == 0 || tallest < students[j][i] )
				{
					tallest = students[j][i];
					tallest_row = j;
				}
			}
			int cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( tallest == students[j][i] ) tallests[j][i] = 1;
			}
		}

		int answer = 0;
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				if ( tallests[i][j] && shortests[i][j] ) answer = students[i][j];
			}
		}

		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#dp

#dp[T] T分での最大幸福 幸福度B、時間A

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

li = [list(map(int,input().split())) for _ in  range(N)]

li = sorted(li,key=lambda x: x[0])

dp = [0]*T
counter = 0
for i in range(N-1):
    A,B = li[i]
    counter = max(counter,max(dp)+B)
    if A>T-1:
        continue
    for t in range(T-A-1,-1,-1):
        dp[t+A]=max(dp[t]+B,dp[t+A])

print(max(max(dp)+li[N-1][1],counter))


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main() {
  string s;
  cin >> s;

  for(int i = 0; i < s.size(); i += 2){
    printf("%c",s[i]);
  }
  printf("\n");
	return 0;
}

Measured memory_bytes: 512
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

ans = []
num = 1
count = 0
for i in range(H):
    tmp = []
    if i % 2 == 0:
        for j in range(W):
            tmp.append(str(num))
            count += 1
            if count == a[num - 1]:
                num += 1
                count = 0
        ans.append(tmp)
    else:
        for j in range(W):
            tmp.insert(0, str(num))
            count += 1
            if count == a[num - 1]:
                num += 1
                count = 0
        ans.append(tmp)


for i in range(len(ans)):
    print(" ".join(ans[i]))


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,c,ans=INF;
    cin>>n>>c;
    VVi d(c,Vi(c)),g(n,Vi(n)),num(3,Vi(c,0)),wa(3,Vi(c,0));
    REP(i,0,c) vin(d[i]);
    REP(i,0,n) vin(g[i]);
    REP(i,0,n) REP(j,0,n) g[i][j]--;
    
    REP(i,0,n){
        REP(j,0,n){
            num[(i+j)%3][g[i][j]]++;
        }
    }
    
    REP(i,0,3){
//        vector<VVi> tmp(3,VVi(c,Vi(c)));
//        int sum=0;
//        REP(j,0,c) sum += num[i][j];
        REP(j,0,c){
            REP(k,0,c){
                wa[i][j] += num[i][k]*d[k][j];
            }
        }
    }
    
    REP(i,0,c){
        REP(j,0,c){
            REP(k,0,c){
                if(i==j || j==k || k==i) continue;
                int tmp = wa[0][i] + wa[1][j] + wa[2][k];
                chmin(ans,tmp);
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin>>N>>M>>K;
	int ans = 0;
	for (int i = N; i <= M;i++){
		if(i%K==0)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,m,k;cin>>n>>m>>k;
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=m;j++){
            ll cnt = i*(m-j) + j*(n-i);
            if(cnt==k)return cout<<"Yes" , 0;
        }
    }
    cout<<"No";
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;

long diff(long a, long b, long c){
    long m = min(a, min(b, c));
    long M = max(a, max(b, c));
    return M-m;
}

int main(){
    long H, W;
    cin >> H >> W;
    if(H%3 == 0 || W%3 == 0){
        cout << 0 << endl;
    }else{
        long ans = abs(H*(W/3)-H*(W/3+1));
        ans = min(ans, abs(W*(H/3)-W*(H/3+1)));
        if(H%2 == 0){
            long a = (H/2)*(W-W/3);
            long b = H*(W/3);
            ans = min(ans, abs(a-b));
            a = (H/2)*(W-W/3-1);
            b = H*(W/3+1);
            ans = min(ans, abs(a-b));
        }else{
            long a = (H/2)*(W-W/3);
            long b = H*(W/3);
            long c = (H/2+1)*(W-W/3);
            ans = min(ans, diff(a, b, c));
            a = (H/2)*(W-W/3-1);
            b = H*(W/3+1);
            c = (H/2+1)*(W-W/3-1);
            ans = min(ans, diff(a, b, c));
        }
        if(W%2 == 0){
            long a = (W/2)*(H-H/3);
            long b = W*(H/3);
            ans = min(ans, abs(a-b));
            a = (W/2)*(H-H/3-1);
            b = W*(H/3+1);
            ans = min(ans, abs(a-b));
        }else{
            long a = (W/2)*(H-H/3);
            long b = W*(H/3);
            long c = (W/2+1)*(H-H/3);
            ans = min(ans, diff(a, b, c));
            a = (W/2)*(H-H/3-1);
            b = W*(H/3+1);
            c = (W/2+1)*(H-H/3-1);
            ans = min(ans, diff(a, b, c));
        }
        cout << ans << endl;
    }
}

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

int min3(int a, int b, int c) {
  if (a <= b && b <= c)
    return a;
  if (b <= a && a <= c)
    return b;
  if (c <= a && a <= b)
    return c;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> vec(n - 1);
  int i, j;
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      vec.at(min3(abs(j - i) - 1, abs(i - x) + 1 + abs(y - j) - 1, abs(i - y) + 1 + abs(j - x) - 1))++;
    }
  }
  
  for (int l = 0; l < n - 1; l++) {
    cout << vec.at(l) << endl;
  }
}

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

int main() {
    long long N,W;
    cin >> N >> W;
    
    if(N == 0 || W == 0){
        cout << 0 <<endl;
        return 0;
    }
    vector<long long>w(N,0);
    vector<long long>v(N,0);
    long long s = 0;
    for(long long i=0;i<N;i++){
        cin >> w[i] >> v[i];
        s+=v[i];
    }
    vector<long long>dp(s+1, 1000000008);
    dp[0] = 0;
    
    for(long long i=0;i<N;i++){
        for(long long j=s;j>=v[i];j--){
            dp[j] = min(dp[j], w[i] + dp[j-v[i]]);
        }
    }
    long long ans = 0;
    for(long long j= 0;j<=s;j++){
      if(dp[j] <= W)ans = j;
    }      
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();

    println!("{}", s.replace("2017", "2018"));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,C,K;
    cin >> N >> C >> K;
    vector<ll> vec(N);
    vecin(vec);
    sort(all(vec));
    ll ans = 0,low = 0,high = 0,cnt = 0;
    rep(i,N){
        if(low == 0){
            low = vec[i];
            high = vec[i] + K;
        }
        if(vec[i] > high || cnt >= C){
            cnt = 1;
            ans++;
            low = vec[i];
            high = vec[i] + K;
            //cout << i << endl;
        }
        else{
            cnt++;
        }
    }
    if(cnt != 0)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3960
#include <vector>
#include <functional>
#include <deque>
#include <stdexcept>

template<typename T, typename Container = ::std::vector<T>, typename Compare = ::std::greater<typename Container::value_type>>
class sliding_window {
    using iterator_type = typename Container::const_iterator;
    using value_compare = Compare;
    using value_type = T;
    using const_reference = const value_type &;

    iterator_type right_bound, left_bound, end;
    value_compare comp;
    size_t length;
    ::std::deque<value_type> val;

public:
    void push() {
        if (left_bound == end) {
            throw ::std::runtime_error("already reached to the end");
        }
        const auto &tmp = *left_bound;
        while (!val.empty() && comp(val.back(), tmp))val.pop_back();
        val.push_back(tmp);
        ++left_bound;
        ++length;
    }

    void pop() {
        if (right_bound == left_bound) {
            throw ::std::runtime_error("interval is empty");
        }
        const auto &tmp = *right_bound;
        if (tmp == val.front())val.pop_front();
        ++right_bound;
        --length;
    }

    sliding_window(iterator_type _begin, iterator_type _end, const Compare &_comp = Compare()) : length(0),
                                                                                                 right_bound(_begin),
                                                                                                 left_bound(_begin),
                                                                                                 end(_end), comp(_comp),
                                                                                                 val({}) {}

    const size_t size() const {
        return length;
    }

    const_reference top() const {
        return val.front();
    }

    void resize(size_t n) {
        if (n < length) {
            while (n < length) {
                pop();
            }
        } else {
            while (n > length) {
                push();
            }
        }
    }

    void forward() {
        if (left_bound != end)push();
        pop();
    }

};

#include <iostream>
#include <algorithm>

int main() {
    unsigned long long N, M, K;
    scanf("%llu%llu%llu", &N, &M, &K);

    std::vector<unsigned long long> A(N), dp1(N), dp2(N);
    for (auto &i : A)scanf("%llu", &i);

    std::copy(A.begin(), A.end(), dp1.begin());

    for (unsigned long long i = 1; i < K; ++i) {
        sliding_window<unsigned long long, std::vector<unsigned long long>, std::less<>> slidingWindow(
                dp1.begin() + i - 1, dp1.end());
        std::transform(A.begin() + i, A.end(), dp2.begin() + i, [&i](auto a) { return a * (i + 1); });

        slidingWindow.push();

        for (unsigned long long j = i; j < N; ++j) {
            dp2[j] += slidingWindow.top();
            if (slidingWindow.size() == M)slidingWindow.pop();
            slidingWindow.push();
        }

        std::swap(dp1, dp2);
    }

    std::cout << *std::max_element(dp1.begin(), dp1.end()) << std::endl;

    return 0;
}

Measured memory_bytes: 2560