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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(all(a));
    vector<pair<ll,ll>> aa;
    ll tmp = a.front();
    ll num = 1;
    for(i = 1;i < n;++i){
        if(a.at(i) == tmp) ++ num;
        else{
            aa.emplace_back(tmp, num);
            tmp = a.at(i);
            num = 1;
        }
    }
    aa.emplace_back(tmp, num);
    n = aa.size();
    i = n-1;
    ll ans = 0;
    while(i >= 0){
        if(aa.at(i).second == 0){
            --i;
            continue;
        }
        ll now = aa.at(i).first;
        --aa.at(i).second;
        tmp = now;
        num = 0;
        while(tmp != 1){
            tmp >>= 1;
            ++num;
        }
        rep(j,num+1) tmp <<= 1;
        ll obj = tmp-now;
        ll ind = lower_bound(all(aa), make_pair(obj,0ll)) - aa.begin();
        if(aa.at(ind).first != obj){
            --i;
            continue;
        }else{
            if(aa.at(ind).second == 0){
                --i;
                continue;
            }else{
                --aa.at(ind).second;
                ++ans;
            }
        }
        if(aa.at(i).second == 0) --i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7408
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
typedef long long int64;
inline int64 read(int f = 1, int64 x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, q, top;
int64 d[N], s[N], f[N];
void solve(int64 p, int64 q)
{
    if(!p) return;
    int r = upper_bound(s+1, s+1+top, p)-s-1;
    if(!r) d[1] += q, d[p+1] -= q;
    else f[r] += p/s[r]*q, solve(p%s[r], q);
}
int main()
{
    s[++top] = n = read(), q = read(); 
    while(q--)
    {
        int64 m = read();
        while(top&&s[top] >= m) --top;
        s[++top] = m;
    }
    f[top] = 1; 
    for(int i = top; i >= 2; --i) 
        f[i-1] += s[i]/s[i-1]*f[i], solve(s[i]%s[i-1], f[i]);
    d[1] += f[1], d[s[1]+1] -= f[1];
    for(int i = 1; i <= n; ++i) printf("%lld\n", d[i] += d[i-1]);
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    ll n, m;
    cin >> n >> m;
    ll s = 0;
    rep(i, m){
        ll a;
        cin >> a;
        s += a;
    }
    if (s > n) cout << -1 << endl;
    else cout << n - s << endl;
    return 0;
}

Measured memory_bytes: 3632
import itertools

n,m,q = map(int,input().split())
abcd = []
l = [i for i in range(1,m+1)]
h = itertools.combinations_with_replacement(l, n)
ans = 0

for i in range(q):
    abcd.append(list(map(int,input().split())))
for v in h:
    sum = 0
    for i in range(q):
        if v[abcd[i][1]-1] - v[abcd[i][0]-1] == abcd[i][2]:
            sum += abcd[i][3]
    ans = max(ans,sum)
print(ans)


Measured memory_bytes: 73576
#include<stdio.h>

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	
	int a[n][m];
	int b[m];
	long c[n];
	
	int i,j;
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf(" %d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf(" %d",&b[i]);
	}
	
	for(i=0;i<n;i++){
		c[i] = 0;
		for(j=0;j<m;j++){
			c[i] += a[i][j]*b[j];
		}
		printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















int main(){
    ll k, x;
    cin >> k >> x;
    cout << ((500 * k >= x)? "Yes" : "No") << endl;
}

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

using namespace std;
int n, t, dp[7001];
pair < int, int > p[7001];
bool cmp(pair < int, int > a, pair < int, int > b){
    if(a.first == b.first){
        return a.second > b.second;
    }
    return a.first < b.first;
}
int main(){
    cin >> n >> t;
    for(int i = 1; i <= n; i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p + 1, p + 1 + n, &cmp);
    for(int i = 1; i <= n; i++){
        for(int j = t - 1; j >= 0; j--){
            dp[j + p[i].first] = max(dp[j + p[i].first], p[i].second + dp[j]);
        }
    }
    cout << *max_element(dp + 1, dp + 6001);
}


Measured memory_bytes: 256
def main():
	N, L = map(int, input().split())
	f_apple = [L + (i + 1) - 1 for i in range(N)]
	f_all = sum(f_apple)

	ans, tmp = 10 ** 8, 0
	for i in range(N):
		tmp = f_all - f_apple[i]
		if abs(tmp - f_all) < abs(ans - f_all):
			ans = tmp

	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;
typedef long long ll;

int N, W;
ll dp[100][100001];//dp[i][j]: i + 1品目まで見て、入れた価値の合計がjだったときの重さの最小値
ll w[100000];
int v[100000];
ll INF = 1145141919810;

int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 100000; j++)dp[i][j] = INF;
	}

	dp[0][0] = 0;
	dp[0][v[0]] = w[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= 100000; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j - v[i] >= 0 && dp[i - 1][j - v[i]] != -1) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			}
		}
	}

	ll ans = 0;
	for (int i = 0; i <= 100000; i++) {
		if (dp[N - 1][i] != INF && dp[N - 1][i] <= W) {
			ans = i;
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n) cin >> vec[i];
    sort(all(vec));
    double ans = (vec[0]+vec[1])/2.0;
    for(int i=1;i<n-1;i++){
        ans = (ans+vec[i+1])/2;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int A=0,B=0,O=0,AB=0;
	int num;
	char blood_type[4];

	while(scanf("%d,%s",&num,&blood_type)!=EOF){
		if(blood_type[0]=='A'){
			if(blood_type[1]=='B'){
			AB++;
		}else{
			A++;
			}
		}else if(blood_type[0]=='B')
			B++;
		else if(blood_type[0]=='O')
			O++;
	}

	printf("%d\n%d\n%d\n%d\n",A,B,AB,O);
	return 0;
}

Measured memory_bytes: 596
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), K = getint();
	int dp[101], h[101] = {};
	dp[K] = 0;
	rep(i, K) dp[i] = 1e9;
	h[K] = getint();

	int k[101];
	rep(i, K + 1) k[i] = i;
	rep(i, N - 1) {
		rep(j, K + 1) k[j]--;
		k[i % (K + 1)] += K + 1;
		h[k[K]] = getint();
		dp[k[K]] = 1e9;
		rep(j, K) chmin(dp[k[K]], dp[k[j]] + abs(h[k[j]] - h[k[K]]));
	}

	printf("%d", dp[k[K]]);

	Would you please return 0;
}

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

int main(){
    map<char,int> m;
    for(int i=0;i<4;i++){
        char c;
        cin>>c;
        m[c]++;
    }
    for(auto p : m){
        if(p.second==2&&m.size()==2){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i+1] < B[i]:
                ans += A[i+1]
                A[i+1] = 0
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
            B[i] = 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81892
#include<iostream>
using namespace std;
const int INF = 10000;

int n;
int d[10];
int D[10];

struct edge {
    int u, v, cost;
    edge() {}
    edge(int uu, int vv, int cc) : 
         u(uu), v(vv), cost(cc) {}
};

edge edges[45];

int main() {
    while (cin>>n) {
    if (n == 0) break;
    int a, b, c;
    int m = 0;
    for (int i = 0; i < n; i++) {
        cin >> a; cin >> b; cin >> c;
        edges[i].u = a;
        edges[i].v = b;
        m = max(a,m); m = max(b,m);
        edges[i].cost = c;
    }
    m++;
    fill(D,D+m,0);
    int res = 0;
    //m 町の数 n道の数
    for (int k = 0; k < m; k++) {
        fill(d,d+m,INF);
        d[k] = 0;
        bool updated = true;
        while (updated) {
            updated = false;
            for (int i = 0; i < n; i++) {
                edge e = edges[i];
                if (d[e.u] != INF && d[e.u] + e.cost < d[e.v]) {
                    updated = true;
                    d[e.v] = d[e.u] + e.cost;
                }
                swap(e.u,e.v);
                if (d[e.u] != INF && d[e.u] + e.cost < d[e.v]) {
                    updated = true;
                    d[e.v] = d[e.u] + e.cost;
                }  
            }
        }
        for (int i = 0; i < m; i++) {
            D[k] += d[i];
        }
    }
    int mm = 0, md = INF;
    for (int i = 0; i < m; i++) {
        if (D[i] < md) {
            mm = i;
            md = D[i];
        }
    }
    cout << mm << " " << md << "\n";
    }
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 3e3 + 50;
const ll mod = 1e9+7;
ll dp[maxn][maxn];
int n;
ll a[maxn];
ll dfs(int l, int r){
    if(dp[l][r]) return dp[l][r];
    if(l == r) return dp[l][r] = a[l];
    ll t1, t2;
    t1 = a[l] - dfs(l+1, r);
    t2 = a[r] - dfs(l, r-1);
    dp[l][r] = max(t1, t2);
    return dp[l][r];
}
int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    printf("%lld\n", dfs(1,n));    
    return 0;
}





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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;

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

int H,W,K;
char fld[1111][1111];
int dist[1111][1111];

signed main(){
    cin>>H>>W>>K;
    rep(i,H)cin>>fld[i];
    int sy,sx;
    rep(i,H)rep(j,W)if(fld[i][j]=='S')sy=i,sx=j;

    queue<pint>que;
    que.push({sy,sx});
    fill_n(*dist,1111*1111,INF);
    dist[sy][sx]=0;
    while(que.size()){
        int y,x;
        tie(y,x)=que.front();
        que.pop();
        rep(d,4){
            int ny=y+dy[d];
            int nx=x+dx[d];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='#'||dist[ny][nx]!=INF)continue;
            dist[ny][nx]=dist[y][x]+1;
            que.push({ny,nx});
        }
    }

    int ans=INF;
    rep(i,H){
        rep(j,W){
            if(dist[i][j]>K)continue;
            int d=min(min(i,j),min(H-1-i,W-1-j));
            chmin(ans,1+(d+K-1)/K);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10752
#include <stdio.h>

int main(void){
  long long K,A,B;
  scanf("%lld%lld%lld",&K,&A,&B);

  long long ans = 1;

  if(B-A > 2 && K >= A+1){
    long long counter = 1;
    K -= A+1;
    ans += B-1;
    ans += (K/2)*(B-A)+K%2;
  }else{
    ans += K;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int64_t N;
  cin>>N;
  vector<int64_t> S(N);
  for(int i=0;i<N;i++) cin>>S.at(i);
  sort(S.begin(),S.end());
  int64_t total=S.at(0);
  for(int i=1;i<N;i++){
    if(2*total<S.at(i)) S.at(i-1)=0;
    total+=S.at(i);
  }
  int64_t ans=0;
  for(int i=0;i<N;i++){
    ans++;
    if(S.at(i)==0) ans=0;
  }
  cout<<ans;
}
    


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	vector<string>inp;
	string foo;  while (cin >> foo) {
		replace(ALL(foo), ',', ' ');
		inp.push_back(foo);
	}
	vector<vector<ll>>num(inp.size());
	REP(i, inp.size()) {
		stringstream ss(inp[i]);
		ll bar; while (ss >> bar) {
			num[i].push_back(bar);
		}
	}
	REP1(i, num.size() / 2) {
		REP(j, num[i].size()) {
			num[i][j] = max({ num[i][j], num[i][j] + num[i - 1][max(0LL, j - 1)] ,num[i][j] + num[i - 1][min(i - 1,j)] });
		}
	}
	for (ll i = num.size() / 2 + 1; i < num.size(); ++i) {
		REP(j, num[i].size()) {
			num[i][j] = max({ num[i][j], num[i][j] + num[i - 1][j + 1] ,num[i][j] + num[i - 1][j] });
		}
	}
	cout << num.back().front() << endl;
}






Measured memory_bytes: 3188
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int Y = scan.nextInt();

        int Z = Y - 1000*N;

        for(int y = 0;y<=N;++y){
            if(Z-4000*y <0)break;
            if((Z-4000*y)%9000 == 0){
                int z = (Z-4000*y)/9000;
                int x = N - (y+z);
                if(x >=0){
                    System.out.println(z+" "+y+" "+x);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23252
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    a,b,c = IL()
    k = I()
    cb = 0
    while b<=a:
        b*=2
        cb += 1
    cc = 0
    while c<=b:
        c *= 2
        cc += 1
    if cb+cc<=k:
        print('Yes')
    else:
        print('No')
    exit()

Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

bool is_war(const vector<int>& x, const vector<int>& y){
    for (int Z = -100; Z <= 100; ++Z){
        bool is_ok = true;
        for(int i = 0; i < x.size(); ++i){
            if(x[i] >= Z) is_ok = false;
        }
        for(int i = 0; i < y.size(); ++i){
            if(y[i] < Z) is_ok = false;
        }    
    if (is_ok) return false;
    }
return true;

}

int main(){
    int N,M; cin >> N >> M;
    vector<int> x(N+1), y(M+1);
    cin >> x[0] >> y[0];
    for(int i = 0; i < N; ++i){
        cin >> x[i+1];
    }
    for(int i = 0; i < M; i++){
        cin >> y[i+1];
    }
    if (is_war(x,y)){
        cout << "War" << endl;
    }
    else{
        cout << "No War" << endl;
    }

}


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

int main() {
  int H,W,i,j;
  cin >> H >> W;
  for(i=0;i<W+2;i++) cout << "#";
  cout << endl;
  for(j=0;j<H;j++){
    cout << "#";
    string S;
    cin >> S;
    for(i=0;i<S.size();i++) cout << S.at(i);
    cout << "#" << endl;
  }
  for(i=0;i<W+2;i++) cout << "#";
  cout << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include<vector>
    using namespace std;
    using ll = long long;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    #define rep1(j, m) for (int j = 0; j <= (int)(m); j++)


int main(){

int x,n;
cin >> x >> n;

int a = 101;
int ab = abs(x-a);
int ans = a;


set<int>p;
int tmp;
rep(i,n){
    cin >> tmp;
    p.insert(tmp);    
}

if(n > 0){

while(a > -2){
    //あるかチェック
    if(p.count(a)) {
        a--;
        continue;
    }
    else{
        if(ab >= abs(x-a)){
            ab = abs(x-a);
            ans = a;
        }
        a--;
    }
    
}
}
else
{
    ans = x;
}


cout  << ans << endl;



    
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main()
{
    int n,i;
    cin>>n;
    int a[n+1],count=0;
    for(i=1;i<=n;i++)
     {cin>>a[i];
     }
    for(i=1;i<=n;i++)
     {if(i%2!=0 && a[i]%2!=0)
        {count++;
        }
     }
     cout<<count;

    return 0;
}


Measured memory_bytes: 3588
/*
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define midl (l+r)>>1 
const int maxn=1e6+7;
using namespace std;
int n,l,r,mid,arc[maxn];
bool check(int pp)
{
	if (arc[n]<=pp&&arc[n+1]<=pp) return 1;
	if (arc[n]<=pp&&arc[n-1]<=pp) return 1;
	if (arc[n]>pp&&arc[n+1]>pp) return 0;
	if (arc[n]>pp&&arc[n-1]>pp) return 0;
	rep(i,1,n) 
	 {
	 	if (arc[n+i]<=pp&&arc[n+i+1]<=pp) return 1;
	    if (arc[n-i]<=pp&&arc[n-i-1]<=pp) return 1;
     	if (arc[n+i]>pp&&arc[n+i+1]>pp) return 0;
    	if (arc[n-i]>pp&&arc[n-i-1]>pp) return 0;
	 }
}
int main(){
	scanf("%d",&n);
	rep(i,1,(n<<1)-1) 
	 scanf("%d",&arc[i]);
	for (r=(n<<1)-1,mid=l+r>>1;l<r;mid=l+r>>1)//while(l<r) 
	 if (check(mid)==1) r=mid;
	 else l=mid+1;
	cout<<l;
	return 0;
}
*/
#include<stdio.h>
#define dn(i,j) (a[i]<=k && a[j]<=k)
#define up(i,j) (k<a[i] && k<a[j])

int a[200005],n,l,r,mid;

inline bool judge(const int &k)
{
    if (dn(n-1,n) || dn(n,n+1)) return 1;
    if (up(n-1,n) || up(n,n+1)) return 0;
    for (int i=1;i<n-1;i++)
    {
        if (dn(n+i,n+i+1) || dn(n-i,n-i-1)) return 1;
        if (up(n+i,n+i+1) || up(n-i,n-i-1)) return 0;
    }
    return dn(1,1);
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<n<<1;i++) scanf("%d",a+i);
    for (r=(n<<1)-1,mid=l+r>>1;l<r;mid=l+r>>1) if (judge(mid)) r=mid;else l=mid+1;
    printf("%d",l);
}

Measured memory_bytes: 896
N=int(input())
a=0
for i in range(N):
  if (i+1)//10==0:
    a+=1
  elif (i+1)//100==0:
    a+=0
  elif (i+1)//1000==0:
    a+=1
  elif (i+1)//10000==0:
    a+=0
  elif (i+1)//100000==0:
    a+=1
  else:
    a+=0
print(a)
  


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

void maxHeapfy(int *A, int i, int n) {
	int left, right, largest, tmp;

	left = i * 2;
	right = left + 1;
	if (left <= n && A[left] > A[i]) largest = left;
	else largest = i;
	if (right <= n && A[right] > A[largest]) largest = right;

	if (largest != i) {
		tmp = A[largest];
		A[largest] = A[i];
		A[i] = tmp;
		maxHeapfy(A, largest, n);
	}
}

void buildMaxHeap(int *A, int n) {
	int i;
	for (i = n / 2; i > 0; i--) {
		maxHeapfy(A, i, n);
	}
}

int main() {
	int i, k, n;
	int *A;

	scanf("%d", &n);
	A = (int *)malloc(sizeof(int) * (n + 1));
	for (i = 1; i <= n; i++) {
		scanf("%d", &k);
		A[i] = k;
	}

	buildMaxHeap(A, n);

	for (i = 1; i <= n; i++) {
		printf(" %d", A[i]);
	}
	printf("\n");

	free(A);

	return 0;
}


Measured memory_bytes: 3340
// ※※※ 解答不能 ※※※
// 解き直し.
// ABC 130解説.
// https://img.atcoder.jp/abc130/editorial.pdf
// kyopro_friends氏.
// https://atcoder.jp/contests/abc130/submissions/5979405
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;
const int MAX = 2e3 + 1;
LL dp[MAX][MAX], sum[MAX][MAX], S[MAX], T[MAX];

int main() {
    
    // 1. 入力情報取得.
    LL N, M;
    scanf("%lld %lld", &N, &M);
    // for(int i = 1; i <= N; i++) scanf("%lld", S + i);
    // for(int i = 1; i <= M; i++) scanf("%lld", T + i);
    for(int i = 0; i < N; i++) scanf("%lld", S + i);
    for(int i = 0; i < M; i++) scanf("%lld", T + i);
    
    // 2. 解説通り(※※※ 但し, 理解不能 ※※※).
    // 整数列として等しいような S, T の 部分列の組 の 個数を数える.
    // dp[i][j]: 整数列 S の i番目, 整数列 T の j番目 までで, 条件を満たす 部分列の組 の 個数.
    // S[i] == T[j] の 場合 … dp[i][j] = (Σdp[k][l]) + 1 (但し, 0 < k < i, 0 < l < j)
    // S[i] != T[j] の 場合 … 0
    // -> sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j] で更新するとのこと.
    // -> sum[i - 1][j - 1] + 1 = dp[i][j] から, 
    // -> dp[i + 1][j + 1] - 1 = dp[i][j + 1] - 1 + dp[i + 1][j] - 1 - dp[i][j] - 1 + dp[i][j]
    // -> dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
    // -> dp[i][j] = dp[i - 1][j] + dp[i][j - 1] に 変形して計算？？？？？
    // ※※※ テストケース通らないので, 上記方針は, 誤り(WA版)と判定. ※※※
    // for(int i = 0; i <= N; i++) dp[i][0] = 1;
    // for(int j = 0; j <= M; j++) dp[0][j] = 1;
    // for(int i = 1; i <= N; i++){
    //     for(int j = 1; j <= M; j++){
    //         if(S[i] == T[j]) dp[i][j] = dp[i - 1][j] + dp[i][j - 1], dp[i][j] %= MOD;
    //         else             dp[i][j] = 0;
    //     }
    // }
    
    // 2. 正解者のソースを抜粋.
    for(int j = 0; j <= M; j++) dp[0][j] = 1;
    for(int i = 1; i <= N; i++){
        LL cum[100010] = {};
        for(int j = 0; j <= M; j++){
            dp[i][j] = (dp[i - 1][j] + cum[S[i - 1]]) % MOD;
            cum[T[j]] = (cum[T[j]] + dp[i - 1][j]) % MOD;
        }
    }
    
    // 3. 出力 ～ 後処理.
    printf("%lld\n", dp[N][M]);
    return 0;
    
}

Measured memory_bytes: 32896
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  numS = scanner.nextInt();//要素数
		int arrayS[] = new int[numS];
		
		for(int i = 0; i < numS; i ++ ){
			arrayS[i] = scanner.nextInt();
		}
		int  numT = scanner.nextInt();//要素数
		int arrayT[] = new int[numT];
		
		for(int i = 0; i < numT; i ++ ){
			arrayT[i] = scanner.nextInt();
		}
		
		LinearSearch(numS,arrayS,numT,arrayT);
		
		scanner.close();
	}
	
	public static void LinearSearch(int numS,int[] arrayS,int numT, int[] arrayT){ 
		int count = 0;
		int match = 0;
		int i;
		
		for(i = 0; i < numT; i ++ ){
			count = 0;
			while( count < numS ){
				if(arrayT[i] == arrayS[count]){
					match ++;
					break;
				}
				count ++;
			}
		}
		
		System.out.println(match);	
	}
}


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

int main()
{
    string S;
    cin >> S;

    int countOdd  = 0;
    int countEven = 0;
    int len_S = (int)S.size();
    for (int i = 0; i < len_S; i = i + 2)
    {
        countOdd += (S[i] - '0');
    }
    for (int i = 1; i < len_S; i = i + 2)
    {
        countEven += (S[i] - '0');
    }
    if (countOdd > countEven)
    {
        cout << (((len_S / 2) + (len_S % 2)) - countOdd) + (countEven) << endl;
    }
    else
    {
        cout << ((len_S / 2) - countEven) + (countOdd) << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int a, b, c, d;

int main(){
	cin >> a >> b >> c >> d;
	while(1){
		c -= b;
		if(c <= 0){
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if(a <= 0){
			cout << "No" << endl;
			return 0;
		}
	} 
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
					  // 4 
	                // 3 2 1
	int count = 0;
	for(int i = n-1;i>0;i--)
	{
		count+= i;
	}
	for(int i = m-1;i>0;i--)
	{
		count+= i;
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 2116
#include<iostream>
using namespace std;
 
int main(){
   int n,m,l;
   cin >> n >> m >> l;
   long long matrixA[100][100];
   int matrixB[100][100];
   long long matrixAB[100];
   long long matrixC[100][100];
    
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
           matrixA[i][j] = 0;
       }
   }
    
   for (int i = 0; i < m; i++) {
       for (int j = 0; j < l; j++) {
           matrixB[i][j] = 0;
       }
   }
    
    for (int i = 0; i < n; i++) {
       for (int j = 0; j < l; j++) {
           matrixC[i][j] = 0;
       }
   }
    
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
           cin >> matrixA[i][j]; 
             
       }
   }
    for (int i = 0; i < m; i++) {
       for (int j = 0; j < l; j++) {
           cin >> matrixB[i][j];
       }
   }
    
    
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
           for (int k = 0; k < l; k++) {
             
             matrixC[i][k] += matrixA[i][j] * matrixB[j][k];     
           }
            
       }
   }
    
   for (int i = 0; i < n; i++) {
       for (int k = 0; k < l; k++) {
           if (k) cout << " ";
           cout << matrixC[i][k];
       }
       cout << endl;
   }
    
    return 0;
}

Measured memory_bytes: 3256
// ABC144C.cpp
//#include "pch.h"
#include <iostream>
#include <algorithm> // minを使う
#include <cmath> // sqrtを使う
using namespace std;
int main()
{
	long long N;
	cin >> N;
	long long ans = 1000000000000;
	long long step = 0;
	long long ns = sqrt(N);
	for (long long i = 1; i <= ns; i++)
	{
		if (N%i == 0)
		{
			step = i + N / i - 2;
			ans = min(ans, step);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc=new Scanner(System.in);
      String po=sc.nextLine();
      if(po.length()%2==1)po=po.substring(0,po.length()-1);
      else po=po.substring(0,po.length()-2);
      while(po.length()!=0){
          if(po.substring(0,po.length()/2).equals(po.substring(po.length()/2,po.length())))break;
          else if (po.length()==2)po="";
          else po=po.substring(0,po.length()-2);
      }
      System.out.println(po.length());
    }
}


Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    int i;
    cin >> i;
    cout << n-i+1;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int cnt;
main()
{
    int a,b;
    while(cin>>a>>b,a)
    {
        if(a<b)swap(a,b);
        cnt=0;
        while(b)
        {
            a%=b;
            swap(a,b);
            cnt++;
        }
        cout<<a<<" "<<cnt<<endl;
    }
}


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

int main(){
    int q, h, s, d;
    ll n;
    cin >> q >> h >> s >> d >> n;
    
    vector<pair<int, int> > arr;
    arr.emplace_back(q * 8, 1);
    arr.emplace_back(h * 4, 2);
    arr.emplace_back(s * 2, 3);
    arr.emplace_back(d, 4);
    sort(arr.begin(), arr.end());

    ll ans = 0;
    for(auto a : arr){
        if(n == 0) break;
        switch(a.second){
            case 1: case 2: case 3:
                ans += n * a.first / 2;
                n = 0;
                break;
            case 4:
                if(n >= 2){
                    ans += n / 2 * d;
                    n %= 2;
                }
                break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s;
    int n;
    cin>>s;
    n=s.length();
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else if(i%2==1){
            if(s[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<ll> acc(n + 1, 0);
  rep(i, 0, n) {
    int a;
    cin >> a;
    acc[i + 1] = acc[i] + a;
  }

  ll ans = 1e18;
  rep(i, 1, n) { chmin(ans, abs(acc[i] - (acc[n] - acc[i]))); }
  cout << ans << endl;
}


Measured memory_bytes: 1792
def piyo():
    n = int(input())
    if n>=24:
        if ((n-7)%4==0 or (n-14)%4==0 or (n-21)%4==0 or n%4==0
        or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or (n-24)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=21:
        if ((n-7)%4==0 or (n-14)%4==0 or (n-21)%4==0 or n%4==0
        or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=20:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=16:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=14:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=12:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=8:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=7:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=4:
        if (n%4==0 or (n-4)%7==0 or n%7==0):
            print("Yes")
            return
    print("No")
        
if __name__ == '__main__':
    piyo()

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    ll n, k;
    cin>>n>>k;
    int a[n];
    for (int i = 0; i < n; i++){
        cin>>a[i];
        a[i]--;
    }
    vector<ll> dist(n,0), vis(n,0);
    int u = 0, pre = -1;
    while ((k) && (!vis[u])){
        vis[u]++;
        if (pre>=0) dist[u] = dist[pre]+1;
        pre = u;
        u = a[u];
        k--;
    }
    if ((k>0) && (vis[u])){
        ll c = dist[pre] - dist[u] + 1;
        k%=c;
        while (k--){
            u = a[u];
        }

    }
    cout<<(u+1)<<"\n";
    return 0;
}





Measured memory_bytes: 6716
N = int(input())
S = list(input())
R = []
G = []
B = []

def check(startI, list1, list2, char1, char2):
  num1, num2 = 0, 0
  sub_ = 0
  for num in list1:
    if num > startI:
      if num + (num-startI) < N and S[num+(num-startI)] == char2:
        sub_ += 1
      num1 += 1
  for num in list2:
    if num > startI:
      if num + (num-startI) < N and S[num+(num-startI)] == char1:
        sub_ += 1
      num2 += 1
  return num1 * num2 - sub_


for i in range(N):
  if S[i] == 'R':
    R.append(i)
  elif S[i] == 'G':
    G.append(i)
  elif S[i] == 'B':
    B.append(i)

sum_ = 0
for i in range(N):
  if S[i] == 'R':
    sum_ += check(i, G, B, 'G', 'B')
  elif S[i] == 'G':
    sum_ += check(i, R, B, 'R', 'B')
  elif S[i] == 'B':
    sum_ += check(i, R, G, 'R', 'G')

print(sum_)

Measured memory_bytes: 68492
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 8e3 + 4;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int a, b, c, k;

inline void read() {
    cin >> a >> b >> c >> k;
}

inline void solve() {
    int ans = 0;
    int y = min(a, k);
    ans += y;
    k -= y;
    y = min(b, k);
    k -= y;
    y = min(c, k);
    ans -= y;
    k -= y;
    cout << ans << "\n";
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
        read();
        solve();
//    }

    return 0;
}

Measured memory_bytes: 3652
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		HashMap<Integer, Boolean> n = new HashMap<Integer, Boolean>();
		
		for(int i = 0; i < K; i ++) {
			int d = stdIn.nextInt();
			for(int j = 0; j < d; j ++) {
				int sunuke = stdIn.nextInt();
				if(n.get(sunuke) == null) {
					n.put(sunuke, true);
				}
			}
		}
		System.out.println(N - n.size());
	}
}

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

int main(void) {
	int N, M;
	cin >> N >> M;

	bool cannot = false;
	string ans(N, '@');
	for (int i = 0; i < M; i++) {
		int s;
		char c;
		cin >> s >> c;
		if (ans[s-1] != '@' && ans[s-1] != c) cannot = true;
		else if (N > 1 && s == 1 && c=='0') cannot = true;
		else ans[s-1] = c;
	}
	if (cannot) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < N; i++) {
			if (ans[i]=='@') {
				if (i==0) {
					if (N==1) ans[i] = '0';
					else {
						ans[i] = '1';
					}
				} else {
					ans[i] = '0';
				}
			}
		}
		cout << ans << endl;
	}
  return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())
ans = 0

for i in range(X+1):
    for j in range(X+1-i):
        S = Y - 2*i - 4*j
        if (i + j) > X:
            pass
        elif (i + j) is not X:
            pass
        elif S == 0:
            ans = 1
            break
        else:
            pass



if ans == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, t_8, t_10;
  cin >> A >> B;
  bool Gudge = true;
  
  int i = 0;
  while(Gudge){ 
  i++;
  t_8 = i * 0.08;
  t_10 = i * 0.1;
    if(A == t_8 && B == t_10){
    cout << i << endl;
    Gudge = false;
    }
    if(B < t_10){
    cout << -1 << endl;
    Gudge = false;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll ans;
  ll i=1;
  while(true){
    if(N<=1000*i){
      ans=1000*i-N;
      break;
    }
    else{
      i++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  string S;
  cin >> S;
  
  if(S == "hi" || S == "hihi" || S== "hihihi" || S == "hihihihi" || S == "hihihihihi") {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
// #include <bits/stdc++.h>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <emmintrin.h>

using std::scanf;
using std::printf;
using std::max;
using std::isdigit;

typedef long long ll;

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

#define __my_getchar getchar
inline void read(unsigned int &x){
  x=0;char c;
  while(!isdigit(c=__my_getchar()));
  x=c-'0';
  while(isdigit(c=__my_getchar()))x=10*x+(c-'0');
}

unsigned int n,m;
const int MAX_N = 5000;
const int MAX_M = 200;
unsigned int a[MAX_N] __attribute__((aligned(16)));
unsigned int b[MAX_N * MAX_M] __attribute__((aligned(16)));
unsigned int mx[MAX_M] __attribute__((aligned(16)));

static inline __m128i __attribute__((always_inline))
po_mm_max_epi32(__m128i a, __m128i b){
  __asm__("pmaxsd %1, %0" : "+x" (a) : "xm" (b));
  return a;
}

// // max of two array
// // a[i] = max(a[i], b[i])
// void vec_chmax(int n, unsigned int *a, unsigned int *b){
//   for(int i=0;i<n;i+=4){
//     __m128i xx = _mm_load_si128((__m128i*)(a+i));
//     __m128i yy = _mm_load_si128((__m128i*)(b+i));
//     xx = po_mm_max_epi32(xx,yy);
//     _mm_store_si128((__m128i*)(a+i), xx);
//   }
// }

// // sum of array
// // Σa[i]
// ll vec_sumll(int n, unsigned int *a){
//   __m128i x = _mm_setzero_si128();
//   __m128i y = _mm_setzero_si128();
//   const __m128i zero = _mm_setzero_si128();
 
//   for(int i=0;i<n;i+=4){
//     __m128i xx = _mm_load_si128((__m128i*)(a+i));
//     __m128i yy = _mm_unpackhi_epi32(xx,zero);
//             xx = _mm_unpacklo_epi32(xx,zero);
//     x = _mm_add_epi64(x,xx);
//     y = _mm_add_epi64(y,yy);
//   }
//   x = _mm_add_epi64(x,y);
//   _mm_store_si128((__m128i*)tmp, x);
//   return tmp[0] + tmp[1];
// }

inline ll func(int z,ll sub){
  // vec_chmax(m,mx,b+MAX_M*z);
  // return vec_sumll(m,mx)-sub;
  __m128i x = _mm_setzero_si128(), y = _mm_setzero_si128();
  const __m128i zero = _mm_setzero_si128();
  for(int i=0;i<m;i+=4){
    __m128i xx = _mm_load_si128((__m128i*)(mx+i));
    __m128i yy = _mm_load_si128((__m128i*)(b+MAX_M*z+i));
    xx = po_mm_max_epi32(xx,yy);
    _mm_store_si128((__m128i*)(mx+i), xx);
    yy = _mm_unpackhi_epi32(xx,zero);
    xx = _mm_unpacklo_epi32(xx,zero);
    x = _mm_add_epi64(x,xx);
    y = _mm_add_epi64(y,yy);
  }
  x = _mm_add_epi64(x,y);
  unsigned long long tmp[2] __attribute__((aligned(16)));
  _mm_store_si128((__m128i*)tmp, x);
  return tmp[0]+tmp[1]-sub;
}

int main(){
  read(n);read(m);
  REP(i,n-1)read(a[i]);
  REP(i,n)REP(j,m)read(b[MAX_M*i+j]);

  ll ans = 0;
  REP(l,n){
    ll lensum = 0;
    REP(j,m)mx[j]=0;
    ans = max(ans, func(l,lensum));

    FOR(r,l+1,n){
      lensum += a[r-1];
      ans = max(ans, func(r,lensum));
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 4096
import java.util.*;

public class Main {

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

  void solve() {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

    	int N = cin.nextInt();
    	int K = cin.nextInt();
    	int M = cin.nextInt();
    	
    	// used lesser integer * use current integer;
    	int transit[][] = new int[N + 1][N + 1];
    	transit[0][0] = 1;
    	for( int i = 0; i <= N; ++ i ) {
    		for( int j = 0; i + j <= N; ++j ) {
    			if( i > 0 ) {
    				transit[i][j] = (transit[i][j] + transit[i - 1][j]) % M;
    			}
    			if( j > 0 ) {
        			transit[i][j] = (int)((transit[i][j] + transit[i][j - 1] * (i + 1L)) % M);
    			}
    		}
    	}
    	
    	// used max integer * num used; 
    	long dp[][] = new long[K + 1][N + 1];
    	for( int i = 0; i <= N; ++i ) {
    		dp[1][i] = 1;
    	}
    	
    	for( int newVal = 2; newVal <= K; ++newVal ) {
    		for( int used = 0; used <= N; ++used ) {
    			for( int use = 0; use + used <= N; ++use ) {
    				dp[newVal][used + use] = (dp[newVal][used + use] + dp[newVal - 1][used] * transit[used][use]) % M;
    			}
    		}
    	}
    	
    	System.out.println(dp[K][N]);

    }
    
  }
  
}


Measured memory_bytes: 24404
N = int(input())
A = list()
cnt = 0
A.append(input())
for i in range(N-1):
  x = input()
  if x in A:
    cnt = 1
  elif A[i][-1:] != x[0]:
    cnt = 1
  A.append(x)
print('Yes' if cnt == 0 else 'No')

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

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    if (x*x + y*y <= D*D) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
import numpy as np
h,w=map(int,input().split())
s=[]
for _ in range(h):
    a = input() 
    if "#" in a:
        s.append(a)
d = []
for i in zip(*s):
    if "#" in i:
        d.append(i)
for j in zip(*d):
    print(*j,sep="")

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int answer = 0;
    for(int i = 1; i<=n;i++){
        int j = i;
        int sum = 0;
        while(i != 0){
            sum += i%10;
            i = i/10;
        }
        i = j;
        if(a<=sum && sum <= b){
        //cout << i << " ";
        answer += i;
        }

    }
    cout << answer << endl;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a,b,c; cin>>a>>b>>c;
    string out = a.substr(0,1) + b.substr(1,1) + c.substr(2,1);
    print(out);

     
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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 MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int h,w;
  cin >> h >> w;
  map<char,int>mp;
  rep(i,h){
    rep(j,w){
      char c;
      cin >> c;
      mp[c]++;
    }
  }
  bool ok=true;
  if(h%2==0 && w%2==0){
    for(auto p:mp){
      if(p.second%4!=0)ok=false;
    }
  }
  if(h%2==1 && w%2==0){
    int cnt=0;
    for(auto p:mp){
      if(p.second%2!=0)ok=false;
      if(p.second%4==2)cnt++;
    }
    if(cnt>w/2)ok=false;
  }
  if(h%2==0 && w%2==1){
    int cnt=0;
    for(auto p:mp){
      if(p.second%2!=0)ok=false;
      if(p.second%4==2)cnt++;
    }
    if(cnt>h/2)ok=false;
  }
  if(h%2==1 && w%2==1){
    int cnt1=0,cnt2=0;
    for(auto p:mp){
      if(p.second%4==1 || p.second%4==3)cnt1++;
      if(p.second%4==2)cnt2++;
    }
    if(cnt1!=1 || cnt2>(h+w-2)/2)ok=false;
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
        
}


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

int main() {
	string S;
	char s[4];
	int N;
	int C[4] = { 0 };
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s;
		S = s;
		if (S == "AC") C[0]++;
		else if (S == "WA")C[1]++;
		else if (S == "TLE")C[2]++;
		else if (S == "RE")C[3]++;
	}

	cout << "AC x " << C[0] << '\n';
	cout << "WA x " << C[1] << '\n';
	cout << "TLE x " << C[2] << '\n';
	cout << "RE x " << C[3] << '\n';

	return 0;
}

Measured memory_bytes: 3552
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(register int i=s;i<=t;++i)
int a,b,k;
int main(){
	scanf("%d%d%d",&a,&b,&k);
	printf("%d\n",min(k,b/a));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << max({a+b, a-b, a*b});	
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main(){
  long long a,b,k,i;cin >> a >> b >> k;
  if(b-a+1<=k*2){
    for(i=a;i<=b;i++) cout << i << endl;
  } else {
    for(i=a;i<a+k;i++) cout << i << endl;
    for(i=b-k+1;i<=b;i++) cout << i << endl;
  }
}

Measured memory_bytes: 256