akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<utility>
#include<string>
using namespace std;

pair<string, int> queue[1000000];
string p[100000];
int end_time[100000];

int main(){
    int n, q, start=0, p_top=0;
    string name;
    cin >> n >> q;
    for (int i=0; i<n; i++){
        cin >> queue[i].first >> queue[i].second;
    }
    int top=0, tail=n;
    while (top != tail){
        if (queue[top].second > q){
            queue[tail].second = queue[top].second - q;
            queue[tail].first = queue[top].first;
            top++;
            tail++;
            start+=q;
        }
        else if (queue[top].second ==  q){
            p[p_top] = queue[top].first;
            start+=q;
            end_time[p_top] = start;
            p_top++;
            top++;    
        }
        else{
            p[p_top] = queue[top].first;
            start += queue[top].second;
            end_time[p_top] = start;
            p_top++;
            top++;
        }
    }
    for (int i=0; i<n; i++){
        cout << p[i] << " " << end_time[i] << endl;
    }
}


Measured memory_bytes: 22008
z=[*$<]
m=1<<Math.log2(n=z[0].to_i).ceil
a=[0]*(m*2);
n.times{|i|c=z[1][i];a[i+=m]=1<<c.ord-97
a[i]=a[i*2]|a[i*2|1]while(i/=2)>0}
z[2].to_i.times{|k|t,l,r=z[3+k].split
i=l.to_i+m-1
if ?1==t
a[i]=1<<r.ord-97
a[i]=a[i*2]|a[i*2|1]while(i/=2)>0
else
j=r.to_i+m
x=0
((x|=a[i];i+=1)if i.odd?;x|=a[j-=1]if j.odd?;i/=2;j/=2)while i<j
p (0..25).sum{x[_1]}
end}

Measured memory_bytes: 24936
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  int m,n;

  while( cin >> m , m ){
    P p[m];
    for(int i = 0 ; i < m ; i++ ) cin >> p[i].fr >> p[i].sc ;

    cin >> n;
    P set[n];
    for(int i = 0 ; i < n ; i++ ) cin >> set[i].fr >> set[i].sc ;
    sort( set , set + n );

    for(int i = 0 ; i < n ; i++ ) {
      int x = set[i].fr - p[0].fr , y = set[i].sc - p[0].sc ;
      bool judge = true;
      for(int j = 1 ; j < m ; j++ ) {
        if(!binary_search(set,set+n,P(p[j].fr + x,p[j].sc + y))) judge = false;
      }
      if(judge){
        cout << x << " " << y << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 1172
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
using Graph = vector<vector<int>>;

int dp[100000];

int dfs(const Graph &G, int v){
  for(int i:G[v]){
    if(dp[i] == -1)
      dp[v] = max(dp[v], 1 + dfs(G, i));
    else
      dp[v] = max(1 + dp[i], dp[v]);
  }
  if(dp[v] == -1)
    dp[v] = 0;
  return dp[v];
}

int main(){
  int N, M;cin >> N >> M;
  Graph G(N);
  for(int i = 0;i < M;++i){
    int x, y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
  }
  for(int i = 0;i < N;++i)
    dp[i] = -1;
  int maxv = 0;
  for(int i = 0;i < N;++i){
    maxv = max(maxv, dfs(G, i));
  }
  cout << maxv;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const ll INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {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) {
  for(ll i=0;i<((ll)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    ll n;
    cin >> n;
    if (n == 0) break;
    map<ll, bool> mp;
    mp[13] = true;
    mp[17] = true;
    mp[19] = true;
    mp[23] = true;
    ll l = 55440;
    vvi v(n);
    for(ll i=0;i<(n);++i) {
      ll d;
      cin >> d;
      v[i].resize(d);
      ll t; cin >> t;
      for(ll j=0;j<(d);++j) {
        cin >> v[i][(j + d - t) % d];
      }
    }
    vi tmp(l);
    vi tmp13(13), tmp17(17), tmp19(19), tmp23(23);
    ll ans = 0;
    for(ll i=0;i<(n);++i) {
      if(mp[(ll)(v[i].size())]) {
        ll sz = (ll)(v[i].size());
        if(sz == 13) {
          for(ll j=0;j<(13);++j) {
            tmp13[j] += v[i][j];
          }
        } else if(sz == 17) {
          for(ll j=0;j<(17);++j) {
            tmp17[j] += v[i][j];
          }
        } else if(sz == 19) {
          for(ll j=0;j<(19);++j) {
            tmp19[j] += v[i][j];
          }
        } else {
          for(ll j=0;j<(23);++j) {
            tmp23[j] += v[i][j];
          }
        }
      } else {
        for(ll j=0;j<(l);++j) {
          tmp[j] += v[i][j%(ll)(v[i].size())];
        }
      }
    }
    ll ma = 0;
    for(ll i=0;i<(l);++i) {
      chmax(ma, tmp[i]);
    }
    ans += ma;
    vi hoge = {13, 17, 19, 23};
    for(ll i=0;i<(4);++i) {
      ma = 0;
      if(hoge[i] == 13) {
        for(ll j=0;j<(hoge[i]);++j) {
          chmax(ma, tmp13[j]);
        }
      } else if(hoge[i] == 17) {
        for(ll j=0;j<(hoge[i]);++j) {
          chmax(ma, tmp17[j]);
        }
      } else if(hoge[i] == 19) {
        for(ll j=0;j<(hoge[i]);++j) {
          chmax(ma, tmp19[j]);
        }
      } else {
        for(ll j=0;j<(hoge[i]);++j) {
          chmax(ma, tmp23[j]);
        }
      }
      ans += ma;
    }
    cout << ans << endl;
  }
}



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

int main(){
	
	int a,b; cin>>a>>b;
	for(int i = 0; i < b; i++){
		int x;
		cin>>x;
		a -= x;	}
	if(a <= 0) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  bool flg = false;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] =='T'){
      cnt++;
    }else{
      cnt = 0;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n, q, c, x, y;
	scanf("%d %d", &n, &q);
	int A[100000] = {};
	while (q--){
		scanf("%d %d %d", &c, &x, &y);
		if (c) printf("%d\n", accumulate(A + x, A + y + 1, 0));
		else A[x] += y;
	}
	return 0;
}

Measured memory_bytes: 3140
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := map[string]int{}
	max := 1
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Scan(&tmp)
		_, exists := s[tmp]
		if !exists {
			s[tmp] = 1
		} else {
			s[tmp]++
			if max < s[tmp] {
				max = s[tmp]
			}
		}
	}

	var ans []string
	for k, v := range s {
		if v == max {
			ans = append(ans, k)
		}
	}
	sort.Strings(ans)
	for _, a := range ans {
		fmt.Println(a)
	}

}


Measured memory_bytes: 31744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

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

    long long sum = 0;
    for (long long i = 1; i <= N; ++i) {
        if ((i % 3 != 0) && (i % 5 != 0)) {
            sum += i;
        }
    }
    cout << sum << endl;
    //cout << setprecision(15) << endl;
    return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env python3
s = input()
n = len(s)
ans = 0
f = 0
b = -1
while True:
    if f - b > n - 1:
        break
    nf = s[f] in ("x", s[b])
    nb = s[b] in ("x", s[f])
    ans += "x" in (s[b], s[f]) and s[b] != s[f]
    if nf + nb < 1:
        ans = -1
        break
    f += nf
    b -= nb
print(ans)


Measured memory_bytes: 9108
N = int(input())
upper = [1]

for cnt in [6, 9]:
    tmp = cnt
    while tmp <= 10 ** 5:
        upper.append(tmp)
        tmp *= cnt

dp = [float("inf")] * (10 ** 5 + 1)
dp[0] = 0
for u in upper:
    dp[u] = 1

for i in range(2, N + 1):
    for u in upper:
        if i - u > 0:
            tmp = dp[i - u] + 1
            if tmp < dp[i]:
                dp[i] = tmp

print(dp[N])


Measured memory_bytes: 3828
import java.io.*;

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String p = br.readLine();
		StringBuffer sb = new StringBuffer();
		int i = 0;
		int j = 0;
		int x = 0;

		for( i=0 ; i<s.length() ; i++ ){
			if ( (i+p.length())>s.length() ){
				x = (i+p.length())-s.length();
				sb.append(s.substring(i, s.length())).append(s.substring(0, x));
			}else{
				sb.append(s.substring(i, i+p.length()));
			}
			if( sb.toString().equals(p) ){
				j++;
				break;
			}
			sb.setLength(0);
		}

		if( j==0){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 24468
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n;
cin >> n;
ll a[n+1];
ll b[n];
ll ans = 0;
for (ll i = 0; i < n + 1; i++) cin >> a[i];
for (ll i = 0; i < n ; i++) cin >> b[i];
for (ll i = 0; i < n;i++){
    ll tmp = min(a[i], b[i]);
    ans += tmp;
    b[i] -= tmp;
    a[i] -= tmp;
    ll ttmmpp = min(a[i + 1], b[i]);
    ans += ttmmpp;
    b[i] -= ttmmpp;
    a[i + 1] -= ttmmpp;
}
cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        long m=nl(),v=nl();
        int p=ni();
        long pl=p;
        
        int[]A=new int[n+2];
        A[0]=-1;
        A[n+1]=Integer.MAX_VALUE;
        for (int x=1;x<=n;x++) A[x]=ni();
        Arrays.sort(A);
        
        long vl = m*(v-p);
        int ans=p;
        int b=n-p+1;
        int target=A[b];
        int a=b-1;
        long c=0;
        long ctotal=0;
        int x=b;
        while (A[x]==A[b]) { c++; ctotal+=A[b]; x++; }
        
        while (a>0) {
            long pot=A[a]+m;
            if (pot<target) break;
            
            if (A[a]==A[a+1]) {
                ans++;
            }
            
            else {
                if (c*(A[a]+m)-ctotal+(a-1)*m>=vl) ans++;
                else break;
            }
            
            c++;
            ctotal+=A[a];
            a--;
            
        }
        
        
        System.out.println(ans);
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

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

using namespace std;

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

typedef ll _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 FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll n;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    if(n==0){
        cout << "0" << endl;
        return 0;
    }
    string ans;
    int cnt=1;
    while(true){
        //DEBUG(n);
        ans = to_string(abs(n)%2) + ans;
        n = (n-(abs(n)%2)) / -2;
        if(n==0) break;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;

int main(){
	int n,d,ans=0;
	cin>>n>>d;
	vector<vector<int>>x(n,vector<int>(d));
	rep(i,n)rep(j,d)cin>>x.at(i).at(j);
	rep(i,n)for(int j=i+1;j<n;j++){
		float sum=0;
		rep(k,d)sum+=pow((x.at(i).at(k)-x.at(j).at(k)),2);
		if(sqrt(sum)==ceil(sqrt(sum)))ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

struct choten{
    ll dist1;
    ll dist2;
    vector<ll> leaf;
};
ll n;
choten tree[100010];
bool visited[100010];
void dfs(ll pos, ll from){
    visited[pos] = true;
    rep(i, tree[pos].leaf.size()){
        ll p = tree[pos].leaf[i];
        if(visited[p])continue;
        if(from == 1)tree[p].dist1 += tree[pos].dist1+1;
        else tree[p].dist2 += tree[pos].dist2+1;
        dfs(p, from);
    }
    visited[pos] = false;
}

int main(){
    cin >> n;
    rep(i, n-1){
        ll a, b;
        cin >> a >> b;
        tree[a].leaf.push_back(b);
        tree[b].leaf.push_back(a);
    }
    tree[1].dist1 = 0;
    tree[n].dist2 = 0;
    dfs(1, 1);
    dfs(n, n);
    ll cnt = 0;
    rep(i, n)if(tree[i+1].dist1 <= tree[i+1].dist2)cnt++;
    if(cnt > n/2)cout << "Fennec";
    else cout << "Snuke";
}

Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

typedef pair<int, unsigned int> P;

// Streamline
int main() {
	unsigned int N, M;
	vector<int> X;
	// x is for input only
	int x;
	// input value
	cin >> N >> M;
	for (unsigned int i = 0; i < M; i++)
	{
		cin >> x;
		X.push_back(x);
	}
	// exception
	if (M == 1)
	{
		cout << 0;
		return 0;
	}
	// sort X in a descending order
	sort(begin(X), end(X));

	// "sub" stores difference of X and subscript of X
	vector<P> sub;
	// p is for input only
	P p;
	for (unsigned int i = 1; i < M; i++)
	{
		p.first = X[i] - X[i - 1];
		p.second = i;
		sub.push_back(p);
	}
	// sort sub in a ascending order
	sort(begin(sub), end(sub), greater<>());

	// "group" stores efficient group division of X
	vector<unsigned int> group;
	group.push_back(0);
	group.push_back(M - 1);
	// if piece is more than coordinate
	if (N > M) N = M;
	for (unsigned int i = 0; i < N - 1; i++)
	{
		group.push_back(sub[i].second);
		group.push_back(sub[i].second - 1);
	}
	// sort group in a descending order
	sort(begin(group), end(group));
	
	unsigned int count = 0;
	for (unsigned int i = 1; i <= N * 2; i += 2)
	{
		count += X[group[i]] - X[group[i - 1]];
	}
	cout << count;
}

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

using namespace std;

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

    vector<int> a(N);
    for (int index = 0; index < N; index++) cin >> a[index];
    sort(a.begin(), a.end());

    vector<bool> WIN(K + 1);
    for (int index = a[0]; index < K + 1; index++)
        for (int index2 = 0; index2 < N; index2++)
            if (index - a[index2] < 0) { WIN[index] = false; break; }
  			else if (!WIN[index - a[index2]]) { WIN[index] = true; break; }
  			else if (index2 == N - 1) { WIN[index] = false; break; }

    if(WIN[K]) cout << "First";
    else cout << "Second";

    return 0;
}

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

int main() {
  int A, B, count, s1, s2, s3, s4, s5;
  cin >> A >> B;
  count = 0;
   
  for (int i = A; i <= B; i++) {
    s5 = (i % 10) / 1;
    s4 = (i % 100) / 10;
    s3 = (i % 1000) / 100;
    s2 = (i % 10000) / 1000;
    s1 = (i % 100000) / 10000;
    
    if (s1 == s5) {
      if (s2 == s4) 
        count++;
    }   
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int H,W;
  int i,j;


  while(1){
    scanf("%d %d",&H,&W);

    if(H==0 && W==0)
      break;

    else{
      for(i=0;i<H;i++){
        for(j=0;j<W;j++){
          printf("#");
        }
        printf("\n");
      }
      printf("\n");
    }

  }
  return 0;
}

Measured memory_bytes: 572
h,w=map(int,input().split())
s=float('inf')
for i in range(1,h):
    a1=min(i*w,w*((h-i)//2))
    b1=max(i*w,w*(h-i-(h-i)//2))
    d1=b1-a1
    a2=min(i*w,(h-i)*(w//2))
    b2=max(i*w,(h-i)*(w-w//2))
    d2=b2-a1
    s=min(s,d1,d2)
for j in range(1,w):
    a1=min(j*h,h*((w-j)//2))
    b1=max(j*h,h*(w-j-(w-j)//2))
    d1=b1-a1
    a2=min(j*h,(w-j)*(h//2))
    b2=max(j*h,(w-j)*(h-h//2))
    d2=b2-a2
    s=min(s,d1,d2)
print(s)

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

typedef long long ll;

const ll mod = 1e9 + 7;
ll dp[105][100005];
int a[105];
int main() {
  int n,k;
  cin >> n >> k;

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

  for(int i = 0; i < n; i++) dp[i][0] = 1;
  for(int i = 1; i <= k; i++) dp[0][i] += dp[0][i-1];
  
  for(int i = 0; i < n; i++) {
    for(int j = 1; j <= k; j++) {
      dp[i+1][j] += dp[i][j];
      if(j - a[i] - 1 >= 0){
	dp[i+1][j] -= dp[i][j-a[i]-1];
      }
      dp[i+1][j] %= mod;
      dp[i+1][j] += dp[i+1][j-1];
      
      /* cout << "dp["<<i+1<<"]["<<j<<"] = "<<dp[i+1][j] << endl;
      int x;
      
      cin >> x;
      */
    }
  }

 
  if(k == 0) cout << 1 << endl;
  else {
    cout << (dp[n][k] - dp[n][k-1]) << endl;
  }
}


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

int main() {
    int n, c; cin >> n >> c;
    n += 1;
    int sum = 0;
    for(int i = 0; i < c; ++i) {
        int p; cin >> p;
        sum += p;
    }
    cout << (sum / n) + !!(sum % n) << endl;
}



Measured memory_bytes: 3068
import numpy as np
import copy
D=int(input())

c_list=list(map(int,input().split()))
c_list=np.array(c_list)
c_ll=np.array([0]*26)

d_list=[]
for i in range(D):
    dl=list(map(int,input().split()))
    d_list.append(np.array(dl))

# score
score=0

#expect
for d in range(D):
    c_ll+=1
    exp=[0]*26
    for i in range(26):
        exp[i]+=d_list[d][i]
        c_ll2=copy.deepcopy(c_ll)
        c_ll2[i]=0
        exp[i]-=sum(c_list*c_ll2)

    j=exp.index(max(exp))
    c_ll[j]=0
    print(j+1)

Measured memory_bytes: 27136
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
l = len(a)
b = []
for i in range(l):
  b.append(a[i])
  
ans = 0
Ans = 0
summary = a[0]

if(summary == 0):
  summary = 1
  ans+= 1
  Summary = -1
  Ans+= 1
else:
  b[0] = int(-a[0]/ abs(a[0]))
  Ans+= abs(a[0]- b[0])
  Summary = b[0]  
  
for i in range(1, l):
  if(summary* (summary+ a[i])>= 0):
    if(summary > 0):
      ans+= a[i]+ summary+ 1
      a[i] = -summary- 1 
      summary= -1
    else:
      ans+= -summary+ 1- a[i]
      a[i] = -summary+ 1
      summary= 1
  else:
    summary+= a[i]

for i in range(1, l):
  if(Summary* (Summary+ b[i])>= 0):
    if(Summary > 0):
      Ans+= b[i]+ Summary+ 1
      b[i] = -Summary- 1 
      Summary= -1
    else:
      Ans+= -Summary+ 1- b[i]
      b[i] = -Summary+ 1
      Summary= 1
  else:
    Summary+= b[i]
    
print(min(ans, Ans))

Measured memory_bytes: 14332
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[2000],co,d,e;

	co = 3000;
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];

		if (a[i] < co)
		{
			co = 0;
			co = a[i];
		}
	}
	cin >> d >> e;

	if (d <= e)
	{
		cout << co + d - 50 << endl;
	}
	else if (d > e)
	{
		cout << co + e - 50 << endl;
	}
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
  private static final String POSITIVE = "Positive";
  private static final String NEGATIVE = "Negative";
  private static final String ZERO     = "Zero";
  public static void main(String[] args) {
    int result = 1;
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNextLine()) {
      String line = scanner.nextLine();
      String[] values = line.split(" ");
      
      int a = Integer.parseInt(values[0]);
      int b = Integer.parseInt(values[1]);
      
      if(a > 0) {
        System.out.println(POSITIVE);
      } else if (b > 0) {
        System.out.println(ZERO);
      } else {
        int subtract = Math.abs(a - b);
        if(subtract % 2 == 0) {
          System.out.println(NEGATIVE);
        } else {
          System.out.println(POSITIVE);
        }
      }
      return;
    }
  }
  
}

Measured memory_bytes: 9428
/**
 * There is a start and there is no end in the space. ---Infinity.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the land.
 * It can be said that this is an final ultimatum from the god to the people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

const int N = 200010;

int a[N], MO, n;

inline bool check(int p) {
    int l = p + 1, r = n;
    while(l < r) {
        if(a[l] + a[r] < MO) return false;
        l++;
        r--;
    }
    return true;
}

int main() {
    scanf("%d%d", &n, &MO);
    n <<= 1;
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    std::sort(a + 1, a + n + 1);

    int l = n, r = n; /// [1, l] (l, r]
    while(a[n] + a[l - 1] >= MO && l >= 2) l -= 2;
    while(a[1] + a[r] >= MO && r >= 2) r -= 2;
    l /= 2;
    r /= 2;

    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid * 2)) r = mid;
        else l = mid + 1;
    }

    int p = r * 2;
    int ans = 0;
    l = 1, r = p;
    while(l < r) {
        ans = std::max(ans, a[l] + a[r]);
        l++;
        r--;
    }
    l = p + 1, r = n;
    while(l < r) {
        ans = std::max(ans, (a[l] + a[r]) % MO);
        l++;
        r--;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file
int main()
{
    int c;
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
	if(a>b)
    {
		ll e=a;
		a=b;
		b=e;
	}
	if(a + v*t >= b+w*t)
        cout<<"YES"<<endl;
	else
        cout<<"NO"<<endl;
	return 0;
}


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

using namespace std;

int bubbleSort(vector<int>& A, int N) // N 個の要素を含む 0-オリジンの配列 A
{
    bool flag = true; // 逆の隣接要素が存在する
    int sum = 0;
    while(flag){
	flag = false;
	for(int j = N-1; j >= 1; j--){ // j が N-1 から 1 まで
	    if(A.at(j) < A.at(j-1)){
		// A[j] と A[j-1] を交換
		swap(A.at(j), A.at(j-1));
		sum++;
		flag = true;
	    }
	}
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    
    for(int i = 0; i < N; i++){
	cin >> A.at(i);
    }
    
    int n = bubbleSort(A, N);

    string sep = "";
    for(int i = 0; i < N; i++){
	cout << sep << A.at(i);
	sep = " ";
    }
    cout << endl;
    cout << n << endl;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+100;
int arr[maxn];
int n;
int check(int val)
{
    int ac=val;
    int tp;
    for(int i=0;i<n;++i)
    {
        tp=arr[i]-val;
        val=tp;
    }
    if(tp-ac<0)
        return 1;
    else if(tp-ac>0)
        return 2;
    return 0;
}
int main()
{
    //int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    int l=0,r=arr[0];
    int mid;
    int f;
    while(l<=r)
    {
        mid=l+r>>1;
        f=check(mid);
        if(f==1)
            r=mid-1;
        else if(f==2)
            l=mid+1;
        else
            break;
    }
    int val=mid;
    for(int i=0;i<n;++i)
    {
        cout<<val*2<<" ";
        val=arr[i]-val;
    }
    return 0;
}


Measured memory_bytes: 1664
N=int(input())
B=list(map(int,input().split()))
gou=0
for i in range(N-2):
    if B[i]>=B[i+1]:
        gou+=B[i+1]
    else:
        gou+=B[i]
gou+=B[N-2]+B[0]
print(gou)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < h.length; i++) {
			h[i] = sc.nextInt();
		}
		String ans = "Yes";

		for (int i = n - 1; i > 0; i--) {
			if (n == 1) {
				break;
			}
			else if (h[i] - h[i-1] > -1) {
				continue;

			} else if (h[i] - h[i-1] == -1 ) {
				h[i-1]--;
				continue;

			} else {
				ans = "No";
				break;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 50448
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

const int MOD = 1e9 + 7;

int add(int &x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
}

int main(int argc, char **argv) {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < m; ++i)
		cin >> b[i];

	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for (int i = 0; i < m; ++i)
		dp[n][i] = 1;
	for (int i = 0; i < n; ++i)
		dp[i][m] = 1;
	dp[n][m] = 1;
	for (int i = n - 1; i >= 0; --i)
		for (int j = m - 1; j >= 0; --j) {
			if (a[i] == b[j])
				dp[i][j] = dp[i + 1][j + 1];
			add(dp[i][j], dp[i + 1][j]);
			add(dp[i][j], dp[i][j + 1]);
			add(dp[i][j], MOD - dp[i + 1][j + 1]);
		}

	cout << dp[0][0] << '\n';
	return 0;
}


Measured memory_bytes: 16000
#include <cstdio>
#include <algorithm>

int main()
{
  int n, m; long long l;
  scanf("%d%d%lld", &n, &m, &l);
  long long dist[300][300];
  long long fuel[300][300];
  std::fill((long long*)dist, (long long*)dist + 300 * 300, 1e18);
  std::fill((long long*)fuel, (long long*)fuel + 300 * 300, 1e18);
  for (int i = 0; i < m; ++i)
  {
    int a, b; long long c;
    scanf("%d%d%lld", &a, &b, &c);
    --a, --b;
    dist[a][b] = c;
    dist[b][a] = c;
  }
  for (int k = 0; k < n; ++k)
  {
    for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j < n; ++j)
      {
        dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  for (int i = 0; i < n - 1; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      if (dist[i][j] <= l)
      {
        fuel[i][j] = 1;
        fuel[j][i] = 1;
      }
    }
  }
  for (int k = 0; k < n; ++k)
  {
    for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j < n; ++j)
      {
        fuel[i][j] = std::min(fuel[i][j], fuel[i][k] + fuel[k][j]);
      }
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i)
  {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    printf("%lld\n", fuel[s][t] == 1e18 ? -1 : fuel[s][t] - 1);
  }
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 INF = 1LL << 60;

int main() {
    int a, b; cin >> a >> b;
    if (a <= b) {
        cout << a << endl;
    } else {
        cout << a - 1 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
int h, w;
int H, W;
const int maxN = 505;
int cnt[maxN];
int clr[maxN][maxN];
int val[maxN];
int main() {
   // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    int P = -1;
    if (H % h != 0) {
        P = h;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = i % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    else {
        P = w;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                clr[i][j] = j % P;
                cnt[clr[i][j]]++;
            }
        }
    }
    int mn = 1e8;
    for (int i = 0; i < P; i++) {
        mn = min(mn, cnt[i]);
    }
    bool f1 = false;
    bool f2 = false;
    const int PP = (int)1e9 - 15;
    for (int i = 0; i < P; i++) {
        if (cnt[i] == mn) {
            if (!f1) {
                val[i] = ~PP;
                f1 = true;
            }
        }
        else {
            if (!f2) {
                val[i] = PP;
                f2 = true;
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << val[clr[i][j]] << " ";
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 3840
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();
    int ans = 0;

    for(int i = 0; i < 3; i++){
      if(s.charAt(i) == t.charAt(i)){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
/**
 *   @FileName	d.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.17 21:38:21
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

 
int main() {
    int n,m;cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> que;
    vector<int> ans(n,-1);
    que.push(0);
    ans[0] = 0;
    while(!que.empty()) {
        int q = que.front(); que.pop();
        for(int v : g[q]) {
            if (ans[v] == -1) {
                ans[v] = q + 1;
                que.push(v);
            }
        }
    }
    puts("Yes");
    for (int i = 1; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10112
package main

import (
	"fmt"
)

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func main() {
	var N int
	fmt.Scan(&N)
	h := make([]int, N)
	dp := make([]int, N)
	for n := 0; n < N; n++ {
		fmt.Scan(&h[n])
	}
	for i := range dp {
		h1 := max(i-1, 0)
		h2 := max(i-2, 0)
		dp[i] = min(dp[h1]+abs(h[i]-h[h1]), dp[h2]+abs(h[i]-h[h2]))
	}
	fmt.Println(dp[N-1])
}


Measured memory_bytes: 5504
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();

    long sum = a+b;

    long w = n/sum;
    long p = n%sum;


    System.out.println(w*a+Math.min(p,a));


  }
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}
typedef pair<ll, ll> pll;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k;
	cin >>k;
	
	vector<vector<pii>> r(k);
	rep(i, k){
		r[i].emplace_back((i+1)%k, 1);
		r[i].emplace_back((i*10)%k, 0);
	}
	
	const ll INF = 1e18;
	vector<ll> d(k, INF);
	deque<int> q;
	d[1] = 1;
	q.push_back(1);
	while(!q.empty()){
		int  v = q.front(); q.pop_front();
		for(const auto& rp : r[v]){ 
			int rto = rp.first;
			ll ncst = d[v] + rp.second;
			if(d[rto] > ncst){
				d[rto] = ncst;
				if(rp.second>0) q.push_back(rto);
				else q.push_front(rto);
			}
		}
	}	
	cout <<d[0] <<"\n";
	return 0;
}


Measured memory_bytes: 6656
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b = na()

import math

print(math.ceil((b-1)/(a-1)))

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
for i in range(n-1):
    if a[i+1]==a[i]+1:
        s+=c[a[i]-1]
    s+=b[a[i]-1]
s+=b[a[n-1]-1]
print(s)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n; cin >> n;
        int ans = 0;
        while(n >= 500)
        {
            int x = n/500;
            ans += x*1000;
            n -= (x)*500;
        }
        while(n >= 5)
        {
            int y = n/5;
            ans += y*5;
            n -= y*5;
        }
        cout << ans;
    }    
}

Measured memory_bytes: 3644
import qualified Data.ByteString.Char8 as BC
import qualified Data.Sequence as S
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List

main = do
  k <- readLn :: IO Int
  a <- map bsToInt . reverse . BC.words <$> BC.getLine
  let ans = solve a (2, 2)
  if ans == Nothing
    then print $ negate 1
    else let (l, r) = fromJust ans
         in putStrLn $ show l ++ " " ++ show r

solve :: [Int] -> (Int, Int) -> Maybe (Int, Int)
solve [] (l, r) = Just (l, r)
solve (a:as) (l, r) =
  let m = div l a
      n = div r a
      o = div (l-1) a
  in if n - o > 0
       then if mod l a == 0
              then solve as (a*m, a*(n+1)-1)
              else solve as (a*(m+1), a*(n+1)-1)
       else Nothing

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt


Measured memory_bytes: 17788
n = int(input())
lis = list(map(int, input().split()))
ans = 0

for i in range(n-1):
  if lis[i] > lis[i+1]:
    x = lis[i] - lis[i+1]
    lis[i+1] += x
    ans += x

print(ans)
    
    
  

Measured memory_bytes: 32172
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, d[50];
    int sum=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &d[i]);
    }
    
    rep(i, n-1){
        for (int j=i+1; j<n; j++) {
            sum+=d[i]*d[j];
        }
    }
    
    printf("%d", sum);
    
    return 0;
}



Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int d, n;
    cin >> d >> n;
    if(d == 0){
        if(n == 100) cout << 101 << endl;
        else cout << n << endl;
    }
    else if(d == 1){
        if(n == 100) cout << 10100 << endl;
        else cout << n*100 << endl;
    }
    else{
        if(n == 100) cout << 1010000 << endl;
        else cout << n*10000 << endl;
    }
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			string str = Console.ReadLine();

			long sum = Cnt(str);
			Console.WriteLine(sum);
		}

		static long Cnt(string str)
		{
			long tmp = 0;

			switch (str.Length)
			{
				case 1:
					return long.Parse(str);
				default:
					for (int i = 1; i < str.Length; i++)
					{
						tmp += long.Parse(str.Substring(0, i)) * (long)Math.Pow(2, str.Length - i - 1)
							+ Cnt(str.Substring(i));
					}

					return tmp + long.Parse(str);
			}
				
		}

	}
}


Measured memory_bytes: 13140
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    ll s = 0;
    REP(i, N) {
        cin >> A[i];
        s += A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());
    debug(A);

    if((A[M-1]*4*M)>=s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << 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>
#define rep(i,a,n) for(int i =(a);i<(n);i++)
#define urep(i,a,n) for(int i = (a);i>(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int N, M;
int ans;
string s;
int main() {
	cin >> N;
	int copy = N;
	int num=0;
	while (N != 0) {
		num += N % 10;
		N /= 10;
	}
	if (copy%num == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
def bubbleSort():
    N = int(input())
    lst = list(map(int, input().split()))
    
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(1, N)[::-1]:
            if lst[i-1] > lst[i]:
                lst[i], lst[i-1] = lst[i-1], lst[i]
                count += 1
                flag = 1
    print(*lst)
    print(count)

bubbleSort()

Measured memory_bytes: 7760
using System;

namespace ABC045_A_Trapezoids
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int a = int.Parse(Console.ReadLine());
			int b = int.Parse(Console.ReadLine());
			int h = int.Parse(Console.ReadLine());

			int result = 0;

			result = (a + b) * h / 2;
			
			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

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

    if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) {
        cout << "hon" << endl;
    } else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3604
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
 
int H,N;
vector<pair<int,int>> magic;

int ans = 0;
 
void solve(){
	//体力をh減らすのに必要な最小の魔力をdp[h]とおく。
	vector<int> dp(H+1,2000000000);
	dp[0] = 0;
	for(int h=0;h<=H;h++){
		for(int i=0;i<N;i++){
			int power = magic[i].first;//威力
			int mp = magic[i].second;//消費mp
			dp[min(H,h+power)] = min(dp[min(H,h+power)],dp[h]+mp);
		}
	}
	ans = dp[H];
}
 
int main(){
	cin >> H >> N;
	for(int i=0;i<N;i++){
		int a,b;
		cin >> a >> b;
		magic.push_back(make_pair(a,b));
	}
 
	solve();

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

Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <tuple>
#include<cmath>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define FOR(I,J,K) for(int I = J;I < K;I++)
#define WriteLine(n) cout << n << "\n"; 

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		FOR(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		FOR(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;

int N, A;
llint dp[55][55][2600];
int x[55];

int main() {
	cin >> N >> A;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		//総枚数 : i
		for (int j = 0; j < N; j++) {
			//見てる場所 : j
			for (int k = 0; k <= 2500; k++) {
				//とる
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				//とらない
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	llint ans = 0;
	for (int j = 1; j <= N; j++) {
		for (int k = 0; k <= A * N; k++) {
			if (A * j == k) ans += dp[N][j][k];
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 56448
#include<stdio.h>

int main(){
  int p[100],m[100][100],n,i,j,k,l,o;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
for(l=2;l<=n;l++){
  for(i=1;i<=n-l+1;i++){
    j=i+l-1;
    m[i][j]=1000000;
    for(k=i;k<=j-1;k++){
      o=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      if(o<m[i][j]){
        m[i][j]=o;
      }
    }
  }
}
  printf("%d\n",m[1][n]);
}



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

int parent[(int)2e5+6];
int rnk[(int)2e5+6];
int numOfnodes[(int)2e5+6];
//int maxi=0;

void DSU(){
	for(int i=0;i<(int)2e5+6;i++){
		parent[i]=i;
	}
	for(int i=0;i<(int)2e5+6;i++){
		rnk[i]=0;
		numOfnodes[i]=1;
	}
}

int findparent(int node){
	if(parent[node]==node)return node;
	//c2++;
	//if(maxi<c2)maxi=c2;
	return parent[node]=findparent(parent[node]);
}

bool isConnected(int a,int b){
	if(findparent(a)==findparent(b))return true;
	return false;
}

void connect(int a,int b){
	int tmpa=findparent(a);
	int tmpb=findparent(b);
	if(rnk[tmpa]>rnk[tmpb]){parent[tmpb]=tmpa; numOfnodes[tmpa]+= numOfnodes[tmpb];}
	else if(rnk[tmpa]<rnk[tmpb]){parent[tmpa]=tmpb; numOfnodes[tmpb]+=numOfnodes[tmpa];}
	else {parent[tmpb]=tmpa; rnk[tmpa]++; numOfnodes[tmpa]+= numOfnodes[tmpb];}
}

int main() {
	DSU();
	int nodes,edges,a,b,ans=0;
	cin>>nodes>>edges;
	for(int i=0;i<edges;i++){
		cin>>a>>b;
		if(!isConnected(a,b)){
			connect(a,b);
		}
	}
	for(int i=1;i<=nodes;i++){
		if(findparent(i)==i&&ans<numOfnodes[i])ans=numOfnodes[i];
	}

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


Measured memory_bytes: 6016