akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, k;

const int N = 400005;
const int MOD = 1e9 + 7;
ll fac[N];
ll inv[N];

ll power(ll a, int b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    fac[1] = 1;
    for (int i = 2; i < N; ++i)
        fac[i] = fac[i - 1] * i % MOD;

    inv[N - 1] = power(fac[N - 1], MOD - 2);

    for (int i = N - 2; i >= 0; --i)
        inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll C(int a, int b) {
    return fac[a] * inv[a - b] % MOD * inv[b] % MOD;
}

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

    cin >> n >> k;
    // put n balls into n boxes, empty allowed.
    ll ans = C(2 * n - 1, n - 1);

    if (k < n) {
        int x = n - k; // x boxes cannot be empty
        for (int i = 1; i < x; ++i) {
            // only i boxes are filled, illegal cases.
            // put n balls into i boxes, empty not allowed.
            ans = (ans - C(n, i) * C(n - 1, i - 1) % MOD + MOD) % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
int mod = 1000000007;

/*FUNCs=================================================*/
vi move1 = {0,0,1,-1};
vi move2 = {1,-1,0,0};

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    ll a, b, k; cin >> a >> b >> k;
    ll ans1, ans2;
    if(a > k) {
        ans1 = a-k;
        ans2 = b;
    }
    else {
        ans1 = 0;
        ans2 = b - (k-a);
        chmax(ans2, 0); 
    }
    cout << ans1 << ' ' << ans2 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i, 0, n) cin >> w[i];
    bool f = true;
    set<string> st;
    st.insert(w[0]);
    rep(i, 1, n){
        if(st.count(w[i])) f = false;
        st.insert(w[i]);
        if(w[i][0] != w[i - 1][w[i - 1].size() - 1]) f = false;
    } 
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-05
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    
    int max_water = f / 100, max_sug = max_water * e;
    vector<bool> w(max_water + 1), s(max_sug + 1);
    w[0] = true;
    s[0] = true;
    for (int i = 0; i <= max_water; i++) {
        if (w[i]) {
            if (i + a <= max_water)
                w[i + a] = true;
            if (i + b <= max_water)
                w[i + b] = true;
        }
    }
    for (int i = 0; i <= max_sug; i++) {
        if (s[i]) {
            if (i + c <= max_sug)
                s[i + c] = true;
            if (i + d <= max_sug)
                s[i + d] = true;
        }
    }
    
    pair<double, pair<int,int>> ans = {-1, {-1, -1}};
    for (int i = 0; i <= max_water; i++) {
        if (!w[i]) continue;
        int sugar = i * e;
        for (int j = max_sug; j >= 0; j--) {
            if (s[j] && j <= sugar && i * 100 + j <= f) {
                double density = (double) j / (i * 100 + j);
                if (density > ans.first) {
                    ans.first = density;
                    ans.second = {i * 100 + j, j};
                }
            }
        }
    }
    
    cout << ans.second.first << ' ' << ans.second.second << '\n';
    return 0;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

w,a,b=MI()
if b+w<a:
    ans=a-b-w
elif b>a+w:
    ans=b-a-w
else:
    ans=0
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  cin>>n;
  multiset<int>st;
  int ans=0;
  rep(i,n){
    int a;
    scanf("%d",&a);
    auto it=st.lower_bound(a);
    if(it==st.begin()){
      ans++;
      st.insert(a);
    }
    else{
      --it;
      st.erase(it);
      st.insert(a);
    }
  }
  cout<<st.size()<<endl;
  return(0);
}


Measured memory_bytes: 5372
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;
  cin>>n;
  string s[n];
  int p[n];
  rep(i,n){
    cin>>s[i]>>p[i];
  }
  int ans[n];
  rep(i,n){
    ans[i]=i+1;
  }
  rep(i,n){
    for(int j=n-1;j>i;j--){
      if(s[j]<s[j-1] || (s[j]==s[j-1] && p[j]>p[j-1])){
        int tmp=ans[j];
        ans[j]=ans[j-1];
        ans[j-1]=tmp;
        tmp=p[j]; p[j]=p[j-1]; p[j-1]=tmp;
        string t=s[j];
        s[j]=s[j-1];
        s[j-1]=t;
      }
    }
  }
  rep(i,n){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ACircle {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int r;
        cin >> r;
        cout << r * r << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ACircle solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  while(n!=0 || x!=0){
    int i, j, k;
    int sum =0;
for (i=1;i<=n;i++){
    for (j=i+1;j<=n;j++){
        for (k=j+1;k<=n;k++){
            if(i+j+k == x)
            sum++;
        }
    }
}
        cout<< sum << endl;
        cin >> n >> x;
  }
  return 0;
}





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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 405;

ll n, a[N], dp[N][N], pre[N];

ll sum(int l, int r) {
    return pre[r] - (l ? pre[l - 1] : 0);
}

ll solve(int l, int r) {
    if (l == r)
        return 0;
    if (l + 1 == r)
        return a[l] + a[r];
    ll& ret = dp[l][r];
    if (~ret)
        return ret;
    ret = INF;
    for (int i = l; i < r; ++i)
        ret = min(ret, solve(l, i) + solve(i + 1, r) + sum(l, r));
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

    for (int i = 0; i < n; ++i) 
        cin >> a[i];

    pre[0] = a[0];
    for (int i = 1; i < n; ++i)
        pre[i] = pre[i - 1] + a[i];

    memset(dp, -1, sizeof(dp));
    cout << solve(0, n - 1) << endl;
}

Measured memory_bytes: 1536
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 3000, T = 3000;

int aa[N], bb[N], dp[N][T], dq[N][T];

int main() {
	int n, t; cin >> n >> t;
	for (int i = 0; i < n; i++)
		cin >> aa[i] >> bb[i];
	for (int i = 0; i + 1 < n; i++) {
		int a = aa[i], b = bb[i];
		for (int x = t - 1; x >= 0; x--) {
			dp[i + 1][x] = dp[i][x];
			if (x + a < t)
				dp[i + 1][x + a] = max(dp[i + 1][x + a], dp[i][x] + b);
		}
	}
	for (int i = 0; i + 1 < n; i++) {
		int a = aa[n - 1 - i], b = bb[n - 1 - i];
		for (int x = t - 1; x >= 0; x--) {
			dq[i + 1][x] = dq[i][x];
			if (x + a < t)
				dq[i + 1][x + a] = max(dq[i + 1][x + a], dq[i][x] + b);
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int p = i, q = n - 1 - i;
		for (int x = 0, y = t - 1; x < t; x++, y--)
			ans = max(ans, dp[p][x] + bb[i] + dq[q][y]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 73864
#include "bits/stdc++.h"
using namespace std;

typedef pair<long long, long long> P;
long long INF = 1145141919810364364;

int main() {
	int N, M, S, T;
	static long long YenDis[100000], SnuukDis[100000], ANS[100000];
	static vector<P> Yen[100000], Snuuk[100000];
	priority_queue<P, vector<P>, greater<P> > PQYen, PQSnuuk;
	cin >> N >> M >> S >> T;
	S--, T--;
	for (int i = 0; i < N; i++) {
		YenDis[i] = INF;
		SnuukDis[i] = INF;
	}
	YenDis[S] = 0;
	SnuukDis[T] = 0;
	for (int i = 0; i < M; i++) {
		long long U, V, A, B;
		cin >> U >> V >> A >> B;
		U--, V--;
		Yen[U].push_back(P(A, V));
		Yen[V].push_back(P(A, U));
		Snuuk[U].push_back(P(B, V));
		Snuuk[V].push_back(P(B, U));
	}
	for (P p : Yen[S]) PQYen.push(p), YenDis[p.second] = p.first;
	for (P p : Snuuk[T]) PQSnuuk.push(p), SnuukDis[p.second] = p.first;
	while (PQYen.size()) {
		P p = PQYen.top();
		PQYen.pop();
		for (P q : Yen[p.second]) {
			if (YenDis[q.second] > YenDis[p.second] + q.first) {
				YenDis[q.second] = YenDis[p.second] + q.first;
				PQYen.push(q);
			}
		}
	}
	while (PQSnuuk.size()) {
		P p = PQSnuuk.top();
		PQSnuuk.pop();
		for (P q : Snuuk[p.second]) {
			if (SnuukDis[q.second] > SnuukDis[p.second] + q.first) {
				SnuukDis[q.second] = SnuukDis[p.second] + q.first;
				PQSnuuk.push(q);
			}
		}
	}
	ANS[0] = YenDis[N - 1] + SnuukDis[N - 1];
	for (int i = 1; i < N; i++) {
		ANS[i] = min(ANS[i - 1], YenDis[N - 1 - i] + SnuukDis[N - i - 1]);
	}
	for (int i = N - 1; i >= 0; i--) {
		cout << 1000000000000000 - ANS[i] << endl;
	}
}


Measured memory_bytes: 25200
R=range(8)
A=[4,1,4,1,2,1,2,1]
A+=A
B="41412121"
B=map(int,[B[i:]+B[:i] for i in R])

import sys
for s in sys.stdin:
  x=map(int,s[:-1].split())
  m=sum(x)
  for i in R:
    s=sum([max(0,x[j]-A[i+j]) for j in R])
    if s<m:
      m=s
      p=B[i]
    elif m==s and B[i]<p: p=B[i]
  print " ".join(list(str(p)))

Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

void solve() {
	int h, n;
	cin >> h >> n;
	vi a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	
	int mx = 0;
	for(int i = 0; i < n; i++) mx = max(mx, a[i]);
	
	int dp[1000010];
	fill(dp, dp + 1000010, 1e9);
	dp[0] = 0;
	for(int j = 0; j + mx < 1000010; j++) {
		for(int i = 0; i < n; i++) {
			dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
		}
	}
	
	int mn = 1e9;
	for(int i = h; i < 1000001; i++) mn = min(mn, dp[i]);
	
	cout << mn << endl; 
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    r(i, n) cin >> v[i];
    int q, k, p;
    cin >> q;
    while (q--) {
        cin >> k;
        cout << lower_bound(v.begin(),v.end(),k)-v.begin() << " " << upper_bound(v.begin(),v.end(),k)-v.begin() << endl;
    }
    return 0;
}


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

using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

template<typename T>
inline void input(T &a) {
    static int ed;
    a = 0;
    while (!isdigit(ed = getchar()) && ed != '-') { }
    char neg = 0;
    if (ed == '-') {
        neg = 1;
        ed = getchar();
    }
    while (isdigit(ed)) {
        a = 10 * a + ed - '0';
        ed = getchar();
    }
    if (neg) a = -a;
}

template<typename T = int>
inline T nxt() {
    T res;
    input(res);
    return res;
}


typedef long long ll;
typedef pair<ll, ll> pll;

//const int N=1e5+7;
ll f(ll n, ll d){
    ll ans = n/d;
    if(n%d) ans++;
    return ans;
}
int main(){
    fast;
    ll n,x,y,a=0,b=0,r;
    cin>>n;
    cin>>a>>b;
    forn(i,n-1){
        cin>>x>>y;
        r=max(f(a,x), f(b,y));
        a=r*x;
        b=r*y;
        //cout<<a<<" "<<b<<endl;
    }
    cout<<a+b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long ans = 0;
    if ((A + B) / 2 >= C)
    {
        /*
        long long min_num = min(X, Y);
        ans += min_num * 2 * C;
        X -= min_num;
        Y -= min_num;
        if (A <= 2 * C || B <= 2 * C)
        {
            
            ans += A * X + B * Y;
        }
        else
        {
            ans += max(X, Y) * 2 * C;
        }
        */
        ans += 2 * C * min(X, Y);
        if (X > Y)
        {
            ans += (X - Y) * min(A, C * 2);
        }
        else
        {
            ans += (Y - X) * min(B, C * 2);
        }
    }
    else
    {
        ans += A * X + B * Y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int N, M;
  vector<string> s, t;
  cin >> N;
  s.resize(N);
  for(int i = 0; i < N; i++) cin >> s[i];
  cin >> M;
  t.resize(M);
  for(int i = 0; i < M; i++) cin >> t[i];

  vector<string> LIST;
  for(int i = 0; i < N; i++){
    if(find(LIST.begin(), LIST.end(), s[i]) == LIST.end()) LIST.push_back(s[i]);
  }

  int ans = 0;
  for(auto str : LIST){
    int tmp = 0;
    for(int i = 0; i < N; i++){
      if(s[i] == str) tmp++;
    }
    for(int i = 0; i < M; i++){
      if(t[i] == str) tmp--;
    }
    if(tmp > ans) ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, 1, 0, -1};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;
	int n = s.size();
	if (t.substr(0, n) == s)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int e;
    while(cin>>e, e){
        int ans = INF;
        for(int z=0; z*z*z<=e; z++){
            int sum = z*z*z;
            for(int y=0; y*y+sum<=e; y++){
                int x = e-y*y-sum;
                ans = min(ans, x+y+z);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
class LazySegTree:
    INF = 0
    def __init__(self,n_):
        self.n_ = n_
        self.n = 1
        while self.n < n_: self.n*=2
        self.lazy = [self.INF]*(2*self.n-1)

    def update(self,a,b,k,x,l,r):
        if r<=a or b<=l :return
        if a<=l and r<=b:
            self.lazy[k] += x
            return
        self.update(a,b,k*2+1,x,l,(l+r)//2)
        self.update(a,b,k*2+2,x,(l+r)//2,r)

    def Update(self,a,b,x):
        return self.update(a,b,0,x,0,self.n)

    def search(self,k,l,r):
        k += self.n-1
        res = self.INF
        while 0<=k:
            res += self.lazy[k]
            k = (k-1)//2
        return res

    def Search(self,k):
        return self.search(k,0,self.n)

def main():
    n,m = map(int,input().split())
    lst = LazySegTree(n)
    for _ in range(m):
        q = list(map(int,input().split()))
        if q[0] == 0:
            lst.Update(q[1]-1,q[2],q[3])
        else        :
            print(lst.Search(q[1]-1))

if __name__ == '__main__':
    main()




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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int a, b; cin >> a >> b;

    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << (a + b) / 2 + 1 << endl;
    }
}

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

int main() {
  char c1[3];
  char c2[3];
  cin >> c1;
  cin >> c2;
  if (c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll p, q, r; cin>>p>>q>>r;
    ll m = max(max(p,q), r);
    cout << p + q + r -m <<endl;
    return 0;
}

Measured memory_bytes: 256
require 'pp'

chs = gets.chomp!.chars

ans = []

count = 1
head = 0
tail = 1
while chs.length >= 2
    ch1 = chs.shift
    ch2 = chs.shift
    if ch1 != ch2
        chs.unshift(ch2)
        ans << ch1
    else
        ch3 = chs.shift
        if ch3
            chs.unshift(ch2 + ch3)
            ans << ch1
        else
            chs.unshift(ch1 + ch2)
        end
    end

    #pp chs
    #pp ans
end

puts chs.length + ans.length


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

using namespace std;


#define MAXN 200001
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a[MAXN];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    if (a[0] || (i && a[i]>a[i-1]+1)) {
      cout << -1 << endl;
      return 0;
    }
  }
  ll cur = 0, ans = 0;
  for (int i = n-1; i >= 0; --i) {
    if (a[i]!=cur) {
      cur = a[i];
      ans += cur;
    }
    --cur;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int n,k,x,ans=0;
    cin >>n>>k;
    for range(i,n){
        cin >>x;
        ans+=min(2*x,2*abs(k-x));
    }
    cout << ans << endl;

}   

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define MN 300
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,ans;
char s[MN+5][MN+5];
int main()
{
    n=read();
    for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
    for(int k=0;k<n;++k)
    {
        int flag=1;
        for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
            if(s[i][(j+k-1)%n+1]!=s[j][(i+k-1)%n+1]) flag=0;
        if(flag) ans+=n;
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

using ll = long long;

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

    std::vector<std::pair<ll, ll>> students(N);
    for (ll i = 0; i < N; ++i) {
        cin >> students[i].first;
        students[i].second = i + 1;
    }

    std::sort(students.begin(), students.end());

    std::for_each(students.cbegin(), students.cend() - 1, [](const auto &x) { cout << x.second << " "; });
    std::cout << (students.cend() - 1)->second << endl;


    return 0;
}


Measured memory_bytes: 2432
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
t = [0] * (2 * n + 10)
t[0] = a[0]
for i in range(0, n-1):
  t[2*i+1] = a[i+1]
  t[2*i+2] = a[i+1]
a = t[:n-1]
print(sum(a))

Measured memory_bytes: 93932
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a, a+4);
	if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.readline

def main():
    h,w,k=map(int,input().split())
    s=[list(input()) for _ in range(h)]
    cnt=[[0]*(w+1) for _ in range(h+1)]#計算しやすくするために0の一に余剰なマスを入れてある

    for i in range(1,h+1):
        for j in range(1,w+1):
            flg=int(s[i-1][j-1])
            if i==0 and j==0:
                cnt[i][j]=flg
            elif i==0:
                cnt[i][j]=cnt[i][j-1]+flg
            elif j==0:
                cnt[i][j]=cnt[i-1][j]+flg
            else:
                cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+flg
    ans=h+w+1
    for p in range(1<<(h-1)):
        g=[0]*(h+1)
        gnum,gcnt=0,0
        for i in range(h-1):
            if p>>i&1:
                gnum+=1
                g[gnum]=i+1
        gcnt+=gnum
        gnum+=1
        g[gnum]=h
        sw,j=1,2
        while j<=w:
            for i in range(1,gnum+1):
                if cnt[g[i]][sw]-cnt[g[i]][sw-1]-cnt[g[i-1]][sw]+cnt[g[i-1]][sw-1]>k:
                    gcnt=h+w+2
                    j=w
                    break            
            for i in range(1,gnum+1):
                if cnt[g[i]][j]-cnt[g[i]][sw-1]-cnt[g[i-1]][j]+cnt[g[i-1]][sw-1]>k:
                    sw=j
                    gcnt+=1
                    break
            j+=1
        ans=min(ans,gcnt)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43740
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n == 1)System.out.println("Hello World");
      if(n == 2){
      	int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a+b);
        sc.close();
      }
    }
}

Measured memory_bytes: 21844
/************************************/
/* NoobM							*/
/* File Name : cha.cpp				*/
/* Date : 13.07.2020 02:20:47 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	ll n, m;
	cin >> n >> m;
	
	ll g = n * m;
	
	if(n == 1 || m == 1) cout << 1 << endl;
	else cout << g / 2 + g % 2<< endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>

int main()
{
	int a[10000];
	int i,k;
	
	i=0;
	
	while(1){
	scanf("%d",&a[i]);
	if(a[i]==0){
		break;
		return 0;
	}
	i++;
	}
	
	for(k=0;k<i;k++){
		printf("Case %d: %d\n",k+1,a[k]);
	}
	
return 0;
}

Measured memory_bytes: 636
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		
		int ans = 0;
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					if (500 * i + 100 * j + 50 * k == x) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 22608
while True:
    N, M = map(int, input().split())
    if N == 0 and M == 0: break
    r = int(input())
    students = [{'start': [], 'end': [], 'login': []} for _ in range(M)]
    for _ in range(r):
        t, n, m, s = map(int, input().split())
        n -= 1; m -= 1
        if s == 1:
            if len(students[m]['login']) == 0:
                students[m]['start'].append(t)
            students[m]['login'].append(n)
        elif s == 0:
            students[m]['login'].remove(n)
            if len(students[m]['login']) == 0:
                students[m]['end'].append(t)
    q = int(input())
    for _ in range(q):
        ts, te, m = map(int, input().split())
        m -= 1
        ans = 0
        for s, e in zip(students[m]['start'], students[m]['end']):
            if s <= ts < te <= e:
                ans = te - ts
                break
            elif s <= ts <= e < te:
                ans += e - ts
            elif ts < s <= te <= e:
                ans += te - s
            elif ts < s < e < te:
                ans += e - s
        print(ans)

Measured memory_bytes: 14664
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using large = long long;
constexpr int mod = 1'000'000'007;

struct X {
    int first;
    int last;
    int mem_cnt;
};

static int solve(const int n, const int k) {
    auto ranges = vector<X>();
    for (int div = 1; div <= n;) {
        auto x = X();
        x.first = div;
        x.last = n / (n / div);
        x.mem_cnt = x.last - x.first + 1;
        ranges.push_back(x);
        div = x.last + 1;
    }

    auto dp = vector<vector<int>>(k + 1, vector<int>(ranges.size()));
    dp[0] = vector<int>(ranges.size(), 1);

    for (int i = 0; i < k; ++i) {
        int acc = 0;
        for (int ri = 0; ri < ranges.size(); ++ri) {
            int cnt = (large(dp[i][ranges.size() - 1 - ri]) * ranges[ri].mem_cnt) % mod;
            dp[i + 1][ri] = ((acc += cnt) %= mod);
        }
    }

    return dp[k][ranges.size() - 1];
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << solve(n, k);
    return 0;
}


Measured memory_bytes: 26232
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int d,n;
    cin>>d>>n;
    int ans=1;
    for(int i=0;i<d;i++){
    	ans*=100;
    }
    if(n==100)n++;
    cout << n*ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n,l;
  cin >> n >>l;
  vector<string> s(n);
  rep(i,n) cin >> s[i];

  sort(s.begin(),s.end());
  rep(i,n) cout << s[i];
  cout << endl;
  return 0;
} 

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

ans=0
for i in range(1,N+1):
    for j in range(i,N+1):
        if i==j:
            if i*j<N:
                ans+=1
            else:
                break
        else:
            if i*j<N:
                ans+=2
            else:
                break
print(ans)

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

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

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

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

using namespace std;

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

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

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

// Problem Specific Parameter:

int main() {
  int n, x; cin >> n >> x;
  int sum = 0;
  vector<int> a(n);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for(int y : a) {
    if(y <= x) {
      x -= y;
      ans++;
    }
  }
  if(x > 0 && ans == n) ans--;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {

    int X, Y;
    cin >> X >> Y;

    for (int a = 0; a <= X; ++a) {
        int b = X - a;
        if(2 * a + 4 * b == Y){
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3132
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))

smax=0
for i in range(n):
    s=0
    for ii in range(i+1):
        s+=a1[ii]
    for ii in range(i,n):
        s+=a2[ii]
    smax=max(s,smax)
print(smax)
        


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


int main() {
  int N;
  int A[210];
  cin >> N;
  
  for (int i=0;i<N;++i) cin >> A[i];
  
  int counter;

  
  while (true){
    bool flag = false;
    for(int i = 0;i<N;++i){
      if(A[i]%2==1) {
        flag=true;break;
      }else{
        A[i]/=2;
      }
    }
    if (flag) break;
    ++counter;
  }
  
  cout << counter << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e6 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

int a[N];

int main () {
	boost;
	int n, k, q;
	cin >> n >> k >> q;
	for (int i = 0 ; i < n ; ++ i)
		a[i] = q;
	while (q--) {
		int pos;
		cin >> pos;
		--pos;
		--a[pos];
	}
	for (int i = 0 ; i < n ; ++ i) {
		if (a[i] < k) cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 1024
//--- pA ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int s = reader.ni();
		int w = reader.ni();
		if (w >= s) {
			out.println("unsafe");
		} else {
			out.println("safe");
		}
		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 32988
#include<stdio.h>
int main()
{

long long int a,b,c,d,sum;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
if(a>b)
{
sum=b*c+(a-b)*d;



}
if(a<=b)
{
sum=a*c;


}

printf("%lld\n",sum);
return 0;




}


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

int n;
int main() {
  cin >> n;
  
  int cnt = 0;
  int mn = n + 1;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a < mn) {
      mn = a;
      ++cnt;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

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

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int h,w;
    cin>>h>>w;
    P s,g;
    cin>>s.first>>s.second>>g.first>>g.second;
    s.first--;
    s.second--;
    g.first--;
    g.second--;
    vector<string> m(h);
    rep(i,h)cin>>m[i];
    vector memo(h,vector(w,MOD));
    memo[s.first][s.second]=0;
    priority_queue<pair<int,P>,vector<pair<int,P>>,greater<>> que;
    que.emplace(0,s);
    while(!que.empty()){
        auto [a,b]=que.top();que.pop();
        auto [x,y]=b;
        if(memo[x][y]!=a)continue;
        memo[x][y]--;
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(0<=nx&&0<=ny&&nx<h&&ny<w&&m[nx][ny]=='.'&&memo[nx][ny]>a){
                memo[nx][ny]=a;
                que.emplace(a,P(nx,ny));
            }
        }
        rep(i,-2,3){
            rep(j,-2,3){
                int nx=x+i,ny=y+j;
                if(0<=nx&&0<=ny&&nx<h&&ny<w&&m[nx][ny]=='.'&&memo[nx][ny]>a+1){
                    memo[nx][ny]=a+1;
                    que.emplace(a+1,P(nx,ny));
                }
            }
        }
    }
    if(memo[g.first][g.second]==MOD)cout<<-1<<endl;
    else cout<<memo[g.first][g.second]+1<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

int MAX_V = 100000;

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> w(N),v(N);
  REP(i,N){
    cin >> w[i] >> v[i];
  }

  vector<ll> dp(MAX_V+1,INF);
  dp[0]=0;

  REP(i,N){
    for(int j = MAX_V; j >=0; j--){
      if(dp[j]==INF)continue;
      if(dp[j]+w[i]>W)continue;
      dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]); 
    }
  }

  int ans=0;
  REP(i,MAX_V+1){
    if(dp[i]==INF)continue;
    ans = max(ans,i);
  }
  cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N; cin>>N;
  vector<int> W(N);
  int ttl=0;  
  for (int i=0;i<N;++i){
    cin>>W[i];
    ttl+=W[i];
  }
  int mini=ttl;
  int tmp=0;
  for (int i=0;i<N;++i){
    tmp+=W[i];
    mini=min(mini,abs(tmp-(ttl-tmp)));
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    edge_weights = [0]*(N+1)
    # edge_weights[i] = iとi+1を繋ぐへんの重み
    for i in range(M):
        edge_weights[a[i]] += 1
        edge_weights[b[i]] -= 1
    
    from itertools import accumulate

    edge_weights = list(accumulate(edge_weights))
    for i in range(N+1):
        if edge_weights[i]%2 == 0:
            continue
        else:
            print(NO)
            return
    
    print(YES)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15596
#include <stdio.h>
#include <string.h>
int main(void)
{
  int n;
  scanf("%d", &n);
  int i, a[n], b[n];
  memset(b, 0, sizeof(int) * (n + 1));
  for (i = 2; i <= n; i++)
  {
    scanf("%d", &a[i]);
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++)
    printf("%d\n", b[i]);
  return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

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

  long a, b;

  cin >> a >> b;

  if (a == b) {
    cout << a*2 << endl;
  } else {
    cout << max(a, b) + max(a-1, b-1) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[16][16];
ll sum[(1<<16)];
ll dp[(1<<16)];
int main(){
	cin>>n;
	rep(i,n)rep(j,n)cin>>a[i][j];
	for(int i=0;i<(1<<n);i++){
		rep(x,n) for(int y=x+1;y<n;y++){
			if( ((i>>x)&1) + ((i>>y)&1) == 2 ){
				sum[i] += a[x][y];
			}
		}
	}
	rep(i,(1<<n)) dp[i] = -1e18;
	dp[0] = 0;
	for(int i=1;i<(1<<n);i++){
		int M = i;
		int cur = (i-1)&M;
		while(1){
			dp[i] = max(dp[i],dp[cur]+sum[i-cur]);
			if(cur == 0) break;
			cur = (cur-1)&M;
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>

using namespace std;
typedef long long ll;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j;
  
    ll K;
    vector<ll> a;

    ll Q,N;
    string S;
    cin>>N;
    ll flag=0;
    ll t1=0;
    ll t2=0;
    for(i=0;i<N;i++){
        cin>>Q;
        a.push_back(Q);
    }

    std::sort(a.begin(),a.end());


ans=a[N/2]-a[N/2-1];

        cout<< ans << endl;
 
}

Measured memory_bytes: 1400
package main

import (
	"fmt"
	"math"
)

func main() {
	var s []byte
	fmt.Scan(&s)


	cnt := 0
	for i := 0; i < len(s); i++ {
		if i % 2 == 0 && s[i] == '0' {
			cnt++
		}
		if i % 2 == 1 && s[i] == '1' {
			cnt++
		}
	}
	cnt2 := 0

	for i := 0; i < len(s); i++ {
		if i % 2 == 0 && s[i] == '1' {
			cnt2++
		}
		if i % 2 == 1 && s[i] == '0' {
			cnt2++
		}
	}
	fmt.Println(min(cnt, cnt2))
}
func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define DEBUG if(0)
#define pb push_back
#define pf push_front
#define mp make_pair
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    double ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	if(i % 2 != 0) ans++;
    }
    printf("%.10lf\n", ans / n);
    return (0);
}

Measured memory_bytes: 256