akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 

 
#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define itt iterator
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define isvowel(a) (a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000020
#define maxn 200005
#define eps 0.0000001

const ll mod=1e9+7;
const ll inf=1e18;

int n;
ll W;

struct node
{
	ll v,w;
};

node a[105];

ll dp[102][100002];

ll find(int i,int rem)
{
	if(i>=n)
	{
		if(rem>0) return inf;
		return 0;
	}
	if(rem==0) return 0;
	if(rem<0) return inf;
	if(dp[i][rem]!=-1) return dp[i][rem]; 
	return dp[i][rem]=min(a[i].w+find(i+1,rem-a[i].v),find(i+1,rem));
}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	cin>>n>>W;

	for(int i=0;i<n;i++)
	{
		int w,v;cin>>w>>v;

		a[i].w=w;
		a[i].v=v;
	}

	initialise(dp,-1);

	int mx=0;

	for(int i=0;i<100001;i++)
	{
		if(find(0,i)<=W) mx=i;
	}
	cout<<mx<<'\n';

	

	return 0;
}

Measured memory_bytes: 80000
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;
const long long inf = (int) 1e18;
const int N = 3005;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  char mat[n + 1][m + 1];
  for (int i = 0; i < n; i++) {
    scanf(" %s", mat[i]);
  }
  long long dp[n + 1][m + 1];
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0) {
        dp[i][j] = 1;
        continue;
      }
      if (mat[i][j] != '.') {
        dp[i][j] = 0;
      } else {
        if (i > 0) {
          dp[i][j] += dp[i - 1][j];
          dp[i][j] %= mod;
        }
        if (j > 0) {
          dp[i][j] += dp[i][j - 1];
          dp[i][j] %= mod;
        }
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
  return 0;
}


Measured memory_bytes: 9088
import numpy as np
mod = 10**9 + 7

N, K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = np.array(A, dtype=object)
B = np.eye(N, dtype=object)

while K > 0:
    if K & 1:
        B = np.dot(B, A) % mod
    A = np.dot(A, A) % mod
    K >>= 1

ans = B.sum() % mod
print(ans)

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
struct dice{
	/*
	1
	2 3 4 5
	6
u:
	4
	1 3 6 5 
	2
d:
	2
	6 3 1 5
	4
l:
	1
	5 2 3 4
	6
r:
	1
	3 4 5 2
	6
	*/
	int a[6];
	void set(vector<int>v){for(int i=0;i<6;i++)a[i]=v[i];}
	void u(){
		vector<int>v={a[3],a[0],a[2],a[5],a[4],a[1]};
		set(v);
	}
	void d(){
		vector<int>v={a[1],a[5],a[2],a[0],a[4],a[3]};
		set(v);
	}
	void l(){
		vector<int>v={a[0],a[4],a[1],a[2],a[3],a[5]};
		set(v);
	}
	void r(){
		vector<int>v={a[0],a[2],a[3],a[4],a[1],a[5]};
		set(v);
	}
}d;
/*
5
6 3 1 4
2
*/
int main(){
	for(int i=0;i<6;i++)cin>>d.a[i];
	d.set({d.a[4],d.a[5],d.a[2],d.a[0],d.a[3],d.a[1]});
	string s;cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='W')d.l();
		else if(s[i]=='E')d.r();
		else if(s[i]=='S')d.d();
		else d.u();
	}
	cout<<d.a[3]<<endl;
	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c<=(a+b)){
        cout<<"No"<<endl;
        return 0;
    }
    if((4*a*b)<((c-a-b)*(c-a-b))) cout<<"Yes"<<endl; else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl

my $n = <STDIN>;
$n =~ s/[\x00-\x20]+$//ios;
my ($k) = map { $_ - 0 } split(/\s+/,<STDIN>);

if( length($n) < $k ){
  print "0\n"; exit(0);
}

my $tot = 0;

if( $k == 1 ){

  # 最大の桁に行きつく前まで
  for(my $p=1;$p<length($n);$p++){
    $tot += 9;  # 一番上の桁のみ
  }
  $tot += (substr($n,0,1) - 0); # 最大桁の場合は一番上で超えない範囲だけ・・

} elsif( $k == 2 ){

  # 最大の桁に行きつく前まで(1桁目固定)
  for(my $p=2;$p<length($n);$p++){
    $tot += 9 * ( $p - 1 ) * 9;
  }
  
  # 最大桁だけ要工夫
  my $top = substr($n,0,1) - 0;
  for(my $i=1;$i<$top;$i++){
    # トップが超えない範囲では、その下の桁は自由に設定できる
    $tot += ( length($n) - 1 ) * 9;
  }
  # トップがちょうどその数字の時、次に出てくる0以外の数字のケタをひろう
  my $i = 1;
  for($i=1; $i<length($n); $i++){
    last if (substr($n,$i,1) - 0) > 0;
  }
  my $keta = length($n) - $i;
  if( $keta > 0 ){
    $tot += ( ( substr($n,$i,1) - 0 ) + ( $keta - 1 ) * 9 );
  }

} elsif( $k == 3 ){

  # 最大の桁に行きつく前まで
  for(my $p=3;$p<length($n);$p++){
    $tot += 9 * &f( $p - 1 );
  }
  
  # 最大桁だけ要工夫
  my $top = substr($n,0,1) - 0;
  
  for(my $i=1;$i<$top;$i++){
    # トップが超えない範囲では、その下の桁は自由に設定できる
    $tot += &f( length($n)-1 );
  }
  
  # トップがちょうどその数字の時、次に出てくる0以外の数字のケタをひろう
  my $i = 1;
  for($i=1; $i<length($n); $i++){
    last if (substr($n,$i,1) - 0) > 0;
  }
  my $keta = length($n) - $i;
  my $key = substr($n,$i,1) - 0; # その場所の数を覚えておく
  
  if( $keta >= 2 ){ # 残り2桁以上ないとだめなので
    
    # ここが0の場合
    $tot += &f( $keta - 1 ) if $keta - 1 >= 2; 
    
    # ここが1~($key-1)
    for(my $j = 1; $j<$key; $j++){
      $tot += 9 * ($keta - 1 );
    }
    
    # ここがkey
    my $j;
    for( $j=$i+1;$j<length($n);$j++){
      last if (substr($n,$j,1) - 0) > 0;
    }
    my $keta2 = length($n) - $j;
    my $key2 = substr($n,$j,1) - 0; # その場所の数を覚えておく
    
    if( $keta2 >= 1 ){
      
      # ここが0の場合
      $tot += 9 * ( $keta2 - 1 ) if ($keta2 - 1 >= 1); # keta2のところが0の場合のとき
      # ここが1以上の場合
      
      $tot += $key2;
    }
  }
}

print "$tot\n";

exit(0);

sub f {
  my $n = shift;
  return ( 9 * 9 * $n * ( $n - 1 ) / 2 );
}



Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,A[1000];


void push(int a){
  
  top++;
  A[top] = a;
}

int pop(){
  top--;
  return A[top+1];
}

int main(){
  int a,b;
  top = 0;
  char B[100];
  while(scanf("%s",B) !=EOF){
    if(B[0] == '+') {
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(B[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if(B[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    
    else{
      push(atoi(B));
    }
  }
  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2044
n = int(input())
location = []
import math
for _ in range(n):
    x,y  = map(int,input().split())
    location.append([x,y])
s = 0
for i in range(n):
    idex=i
    for j in range(n-1):
        idex +=1
        if idex>=n:
            idex=0
        v1 = abs(location[i][0]-location[idex][0])
        v2 = abs(location[i][1]-location[idex][1])
        v = math.sqrt((v1*v1)+(v2*v2))
        s += v*2
print(s/(2*n))

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

int main()
{
  int N;
  int Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for(int a=0;a<=N;++a){
    for(int b=0;a+b<=N;++b){
      int c = N - a - b;
      int total = 10000*a + 5000*b + 1000*c;
      if(total == Y){
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000000;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int n; cin >> n;
	vector<int>x(n);
	rep(i, n) cin >> x[i];
	sort(all(x));
	int ans = INF;
	rep(i, (n+1)/2) {
		int p = (x[i] + x[n - i - 1] + 1) / 2;
		int cnt = 0;
		rep(j, n) {
			int r = abs(x[j] - p);
			r *= r;
			cnt += r;
		}
		ans = min(ans, cnt);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e9+7;

int N;
ll A[100010];
ll ans;
int main(){
    cin>>N;
    REP(i,0,N){
        cin>>A[i];
    }
    REP(i,0,N){
        ans+=A[i]/2;
        if(A[i]%2&&A[i+1]>0){
            ans++;
            A[i+1]--;
        }
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define equals(a, b) (fabs((a) - (b)) < EPS)

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

const int INF = 1 << 28;
const ll LLINF = 1LL << 60;
const double EPS = 1e-9;

int main()
{
    bool flag = true;
    int cnt = 0;
    int N;
    string S, T;
    cin >> S;
    
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != 'x') T.push_back(S[i]);
    }
    N = T.size();
    for(int i = 0; i < N - i - 1; i++) {
        if(T[i] != T[N - i - 1]) flag = false;
    }
    if(flag) {
        int i = 0, j = S.size() - 1;
        while(i < j) {
            int cnt1 = 0, cnt2 = 0;
            while(i < j && S[i] == 'x') i++, cnt1++;
            while(i < j && S[j] == 'x') j--, cnt2++;
            if(S[i] != 'x') cnt += abs(cnt1 - cnt2);
            i++, j--;
        }
        cout << cnt << endl;
    }
    else cout << -1 << endl;

    return (0);
}
    

Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())
X_div = int(X/50)
count = 0
for i in range(1+A):
    for j in range(1+B):
        for k in range(1+C):
            if(10*i + 2*j + k == X_div):
                count += 1
print(count)


Measured memory_bytes: 3060
nums = [int(i) for i in input().split()]

nums = sorted(nums, reverse=True)
diff_2_3 = nums[1] - nums[2]

if diff_2_3 == 0:
    cnt = 0
else :
    q, r = divmod(diff_2_3, 2)
    cnt = q + r
    if r == 1:
        cnt +=1

cnt += nums[0] - nums[1]

print(cnt)

Measured memory_bytes: 3064
s = input()
m2 = int(s[0] + s[1])
u2 = int(s[2] + s[3])

YM = False
MY = False

if m2 < 13 and m2 != 0:
  MY = True
if u2 < 13 and u2 != 0:
  YM = True
if (m2 == 0 and u2 >12) or (u2 == 0 and m2 >12) or (m2 == 0 and u2 == 0):
  YM = False
  MY = False
  
if YM == False and MY == True:
  print('MMYY')
elif MY == False and YM == True:
  print('YYMM')
elif YM == MY == False:
  print('NA')
else:
  print('AMBIGUOUS')

Measured memory_bytes: 3064
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N-1) cin >> C[i];
    int ans = B[A[0]-1];
    rep(i,N-1){
        if(A[i+1]-A[i]==1){
            ans += B[A[i+1]-1] + C[A[i]-1];
        }
        else{
            ans += B[A[i+1]-1];
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
# 演習1-7
while True:
  a,op,b = map(str,input().split())
  a=int(a)
  b=int(b)
  if op == '+':
    result = a+b
    print(result)
  elif op == '-':
    result = a-b
    print(result)
  elif op =='*':
    result = a*b
    print(result)
  elif op=='/':
    result = a//b
    print(result)
  else:
    break


Measured memory_bytes: 5592
n, p = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] %= 2
cnt_zero = a.count(0)
cnt_one = n - cnt_zero
ans = 0
def nCk(n, k):
    if k > n - k:
        return nCk(n, n - k)
    ret = 1
    for i in range(k):
        ret *= n - i
    for i in range(k):
        ret //= i + 1
    return ret
ans = 0
c = 0
for i in range(p, cnt_one + 1, 2):
    c += nCk(cnt_one, i)
ans = (2 ** cnt_zero) * c
print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    int num_negative = 0;
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] < 0) {
            A[i] = -A[i];
            num_negative++;
        }
        sum += A[i];
    }

    if (num_negative % 2 == 0) {
        cout << sum << endl;
    } else {
        sort(A.begin(), A.end());
        cout << sum - 2 * A[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()

    
    ans = 1000-N%1000
    if ans==1000:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 9184
/* ***********************************************
Author        :guanjun
Created Time  :2016/10/11 14:54:59
File Name     :1.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
	int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
	}
};

bool cmp(int a,int b){
    return a>b;
}
typedef pair<ll,int> pii;
vector<pii>v;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    ll h,w,x;
	while(scanf("%lld %lld",&w,&h)!=EOF){
		v.clear();
		for(int i=0;i<w;i++){
			scanf("%lld",&x);
			v.push_back({x,0});
		}
		for(int i=0;i<h;i++){
			scanf("%lld",&x);
			v.push_back({x,1});
		}
		sort(v.begin(),v.end());
		ll ans=0;
		w++;
		h++;
		for(int i=0;i<v.size();i++){
			if(v[i].second==1){
				ans+=w*v[i].first;
				h--;
			}
			else {
				ans+=h*v[i].first;
				w--;
			}
		}
		printf("%lld\n",ans);
	}
    return 0;
}


Measured memory_bytes: 4464
#include<iostream>
using namespace std;
int main(){
    string str;
    cin>>str;
    int len=str.size();
    int sum=0;
    for(int i=0;i<len;i++)sum+=str[i]-'0';
    if(sum%9==0){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=1e9+7;

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

int n,w;
cin>>n>>w;
int a[n],b[n];
int sum=0;
fr(i,0,n){cin>>a[i]>>b[i];sum+=b[i];}

int dp[n][sum+1];
fr(i,0,n)dp[i][0]=0;



fr(j,1,sum+1)
fr(i,0,n)
      if(j>=b[i])
      {if(i==0 && j==b[i])dp[i][j]=a[i]; else if(i==0)dp[i][j]=M; else dp[i][j]=min(a[i]+dp[i-1][j-b[i]],dp[i-1][j]);}
	  else {if(i==0) dp[i][j]=M; else dp[i][j]=dp[i-1][j];}
ll ans=0;
	  fr(i,0,n){fr(j,0,sum+1)if(dp[i][j]<=w)ans=max(ans,j);}
	  
	  //fr(i,0,n){fr(j,0,sum+1)cout<<dp[i][j]<<" ";cout<<endl;}

	  cout<<ans<<endl;
	}





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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

using namespace std;
using p = pair<int, ll>;

class UnionFind
{
    vector<p> data;
public:
    UnionFind(int N)
    {
        data.resize(N+1);
        lpn(i, N+1) data[i] = {i, 1};
    }
    int root(int i)
    {
        if (data[i].first == i) return i;
        auto r = root(data[i].first);
        data[i] = {r, data[r].second};
        return r;
    }
    ll size(int i)
    {
        return data[root(data[i].first)].second;
    }
    void unite(int i, int j)
    {
        auto ri = root(i), rj = root(j);
        data[ri] = data[rj] = {min(ri, rj), size(i) + size(j)};
    }
};

int main(void)
{
    int N, M;
    cin >> N >> M;
    ll temp = (ll)N * (N-1) / 2;
    auto ans = vc(ll, M);
    auto bridges = vc(p, M);
    fa(i, bridges) cin >> i.first >> i.second;
    UnionFind uf(N);
    for (int i = M-1; i >= 0; i--)
    {
        ans[i] = temp;
        if (uf.root(bridges[i].first) != uf.root(bridges[i].second))
        {
            temp -= uf.size(bridges[i].first) * uf.size(bridges[i].second);
            uf.unite(bridges[i].first, bridges[i].second);
        }
    }
    fa(i, ans) cout << i << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  if (N / 1000 == N % 1000 / 100 && N % 1000 / 100 == N % 100 / 10)
  {
    cout << "Yes" << endl;
  }
  else if (N % 1000 / 100 == N % 100 / 10 && N % 100 / 10 == N % 10)
  {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	string S; cin >> S;
	vi ruiseki_r(N, 0);
	vi ruiseki_g(N, 0);
	vi ruiseki_b(N, 0);
	for (int i = N - 1; i > 0; --i) {
		switch (S[i])
		{
		case 'R':
			ruiseki_r[i - 1] = ruiseki_r[i] + 1;
			ruiseki_g[i - 1] = ruiseki_g[i];
			ruiseki_b[i - 1] = ruiseki_b[i];
			break;
		case 'G':
			ruiseki_r[i - 1] = ruiseki_r[i];
			ruiseki_g[i - 1] = ruiseki_g[i] + 1;
			ruiseki_b[i - 1] = ruiseki_b[i];
			break;
		case 'B':
			ruiseki_r[i - 1] = ruiseki_r[i];
			ruiseki_g[i - 1] = ruiseki_g[i];
			ruiseki_b[i - 1] = ruiseki_b[i] + 1;
			break;
		default:
			return;
		}
	}
	// debug(ruiseki_r);
	// debug(ruiseki_g);
	// debug(ruiseki_b);

	ll res = 0;
	REP(i,N) FOR(j,i+1,N) {
		if (S[i] == 'R' && S[j] == 'G') {
			ll tmp = ruiseki_b[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'B') --tmp;
			res += tmp;
		} else if (S[i] == 'R' && S[j] == 'B') {
			ll tmp = ruiseki_g[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'G') --tmp;
			res += tmp;
		} else if (S[i] == 'G' && S[j] == 'R') {
			ll tmp = ruiseki_b[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'B') --tmp;
			res += tmp;
		} else if (S[i] == 'G' && S[j] == 'B') {
			ll tmp = ruiseki_r[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'R') --tmp;
			res += tmp;
		} else if (S[i] == 'B' && S[j] == 'R') {
			ll tmp = ruiseki_g[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'G') --tmp;
			res += tmp;
		} else if (S[i] == 'B' && S[j] == 'G') {
			ll tmp = ruiseki_r[j];
			int k = j + (j - i);
			if (k < N && S[k] == 'R') --tmp;
			res += tmp;
		} else {
			continue;
		}
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
  int n,k;
  int number[1100];
  int i,j,tmp,sum = 0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)
  {
    scanf("%d",&number[i]);
  }


  for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (number[i] > number[j]) {
        tmp =  number[i];
        number[i] = number[j];
        number[j] = tmp;
      }
    }
  }
  for (i=0; i<k; ++i)
  {
    sum += number[i];
  }
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 998244353;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 2e6 + 5;
const long long int MINN = 2e5 + 5;
const long long int inf = 1e6;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 10050;
const int MAXN = 105;
int binsearch(int lo, int hi){
	while(lo<hi){
		int mid=(lo+hi)/2;
		if((mid))   // check(mid)
			hi=mid;
		else
			lo=mid+1;
	}
	return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=((res*x)%MOD);

      y/=2;
      x=((x*x)%MOD);
    }
    return res%MOD;
}

int main(){
    FAST
    int n,m;
    cin>>n>>m;
    int a[n];
    int flag=1,sum=0;
    vii v;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        v.pb({a[i],i});
    }
    sort(v.rbegin(),v.rend());
    if(sum%(4*m)== 0 ){
    for(int i=0;i<m;i++){
        if(v[i].first< sum/(4*m)){
            flag=0; break;
        }
    }
    }
    else{
        for(int i=0;i<m;i++){
            if(v[i].first<= sum/(4*m)){
                flag=0; break;
            }
        }
        }
    
    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
<?php
list($a, $b, $c) = ints();
list($k) = ints();
$cnt = 0;
while ($b <= $a) {
    $b *= 2;
    ++$cnt;
}
while ($c <= $b) {
    $c *= 2;
    ++$cnt;
}
echo $cnt <= $k ? 'Yes' : 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16152
type t = { v : int; w : int }

let solve a n w =
  let dp = Array.make_matrix 2 (w + 1) 0 in
  for i = 1 to n do
    for j = a.(i-1).w to w do
      dp.(1).(j) <-
        if dp.(0).(j - a.(i-1).w) + a.(i-1).v <= dp.(0).(j)
        then dp.(0).(j)
        else dp.(0).(j - a.(i-1).w) + a.(i-1).v;
    done;
    for i = 0 to w do dp.(0).(i) <- dp.(1).(i) done;
  done;
  dp.(1).(w)

let () =
  let (n, w) = Scanf.scanf "%d %d " (fun n w -> n, w) in
  let a = Array.init n (fun _ -> Scanf.scanf "%d %d " (fun v w -> { v; w })) in
  solve a n w |> Printf.printf "%d\n"

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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	char a[100], b[100], c[100];
	scanf("%s %s %s", a, b, c);

	int po = 'a' - 'A';
	printf("%C%C%C\n", a[0] - po, b[0] - po, c[0] - po);
}



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

using namespace std;

int main(void) {

	long long sum=0, max, min,n,m,j;

	cin >> m;

	long long a[10000];

	for (long i = 0; i < m; i++) {

		cin >> a[i];

	}
	sort(a, a + (m));

	max = a[m-1];
	min = a[0];

	for (long i = 0; i < m;i++) {

			sum = sum + a[i];

	}

		cout << min << " " << max << " " << sum << endl;

}

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

int main(void) {
  int n, l[210];
  std::cin >> n;
  for (int i = 0; i < 2 * n; i++) std::cin >> l[i];
  
  std::sort(l, l + 2 * n);
  
  int ans = 0;
  for (int i = 0; i < n; i++) ans += l[2 * i];
  
  std::cout << ans << std::endl;
  
  return 0;
}

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

int main () {
  int N; cin >> N;
  
  int a[105000];
  for (int i=0; i<N; i++) {
    int m;
    cin >> m;
    a[m]++;
  }
  int ans=1;
  for (int i=1; i<104000; i++) {
    int tmp = a[i-1] + a[i] + a[i+1];
    ans = max (ans, tmp);  
  }
  cout << ans << endl;
}


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

int main() {
  ll n, k;
  string s;
  cin >> n >> k;
  cin >> s;

  vector<ll> switches;
  char pre = 'x';

  for (ll i = 0; i < n; i++) {
    if (i != 0 && s[i] != pre)  {
      switches.push_back(i);
    }
    pre = s[i];
  }

  ll cnt = 0;
  if ((ll) switches.size() > 2 * k) {
    cnt = n - 1 - switches.size() + 2 * k;
  } else {
    cnt = n - 1;
  }

  cout << cnt << endl;
}


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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 3000;
ll N;
string s;
ll dp[MAX_N + 1][MAX_N + 1] = {};
//dp[i][j] = (1, 2, ..., i)を並べて末尾がjになるような場合の数の累積和
int main(){
  cin >> N >> s;
  REP(j, N) dp[1][j + 1] = 1;
  FOR(i, 1, N){
    FOR(j, 1, i + 2){
      if(s[i - 1] == '<'){
        dp[i+1][j] = (dp[i + 1][j - 1] + dp[i][j - 1]) % MOD;
      }
      else{
        dp[i+1][j] = (dp[i+1][j-1] + dp[i][i] - dp[i][j-1]) % MOD;
      }
//      printf("dp[%lld][%lld] = %lld\n", i+1, j, dp[i+1][j]);
    }
  }
  cout << (dp[N][N] + MOD) % MOD << endl;
}


Measured memory_bytes: 68992
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S.find("a") != std::string::npos&&S.find("b") != std::string::npos) {
		if (S.find("c") != std::string::npos) {
			std::cout << "Yes";
		}
		else {
			cout << "No";
		}

	}

	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
ll n , m , q ;
ll dp[505][505];
ll pref[505][505];
int main()
{
    ios ;
    memset(dp , 0 , so dp ) ;
    memset(pref , 0 , so pref);
    cin >> n >> m >> q ;
    forn(i , 1 ,m ){
       ll l , r ;
       cin >> l >> r ;
       ll diff = r - l ;
       dp[l][diff]++;
    }
    forn(city , 1 , n){
       forn(diff , 0 , n-1){
           if(diff == 0 ){
            pref[city][diff] = dp[city][diff];
           }
           else{
            pref[city][diff] = pref[city][diff-1] + dp[city][diff];
           }
       }
    }
    forn(i , 1 , q){
       ll pi , qi ;
       cin >> pi >> qi ;
       ll cnt  =  0 ;
       forn(i , pi , qi){
          ll diff = abs(qi - i);
          cnt = cnt + pref[i][diff] ;
       }
       cout << cnt << el ;
    }
}






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

int a[100010];
int n,m;
vector <int> v[100010];
int ans;

bool cmp(int x,int y)
{
	return a[x] < a[y];
}

int main()
{
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	for (int i = 1;i <= m;i ++)
	{
		int x,y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for (int i = 1;i <= n;i ++)
	{
		bool f = true;
		for (int j = 0;j < v[i].size();j ++)
			if (a[v[i][j]] >= a[i]) f = false;
		if (f) ans ++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8680
using System;
using static System.Math;
public class hello
{
	static int dpmax;
	public static void Main()
	{

		string[] line = Console.ReadLine().Trim().Split(' ');
		var m = int.Parse(line[0]);
		var n = int.Parse(line[1]);
		dpmax = 1 << n;
		var book = getData(m);
		var s = getData(n);
		var book2 = getCsum(book, m);
		var dp = new int[dpmax];
		for (int i = 1; i < dpmax; i++) dp[i] = -10;
		dp[0] = -1;
		var ans = getAns(dp, book2, m, s, n);
		Console.WriteLine(ans == 0 ? 0 : ans + 1);
	}
	static int getAns(int[] dp, int[,] book2, int m, int[,] s, int n)
	{
		var ans = 0;
		for (int i = 0; i < dpmax; i++)
		{
			if (dp[i] == m - 1) return m - 1;
			for (int j = 0; j < n; j++)
			{
				if (dp[i] != -10)
					if (((i >> (n - j - 1)) & 1) == 0)
					{
						var ww = i | (1 << (n - j - 1));
						var t = goBS(book2, m, s, n, j, dp[i] + 1);
						if (t != -1)
						{
							dp[ww] = Max(dp[ww], t);
							ans = Max(ans, dp[ww]);
						}
					}
			}
		}
		return ans;
	}
	static int goBS(int[,] book2, int m, int[,] s, int n, int t, int next)
	{
		if ((book2[m, 0] - book2[next, 0] <= s[t, 0]) && (book2[m, 1] - book2[next, 1] <= s[t, 1]))
			return m - 1;
		if ((book2[next + 1, 0] - book2[next, 0] > s[t, 0]) | (book2[next + 1, 1] - book2[next, 1] > s[t, 1]))
			return -1;
		var ok = next;
		var ng = m - 1;
		while (ng - ok > 1)
		{
			var mid = ok + (ng - ok) / 2;
			if ((book2[mid + 1, 0] - book2[next, 0] <= s[t, 0]) && (book2[mid + 1, 1] - book2[next, 1] <= s[t, 1]))
				ok = mid;
			else ng = mid;
		}
		return ok;
	}
	static int[,] getCsum(int[,] a, int n)
	{
		var ans = new int[n + 1, 2];
		for (int i = 0; i < n; i++)
		{
			ans[i + 1, 0] = ans[i, 0] + a[i, 0];
			ans[i + 1, 1] = ans[i, 1] + a[i, 1];
		}
		return ans;
	}
	static int[,] getData(int n)
	{
		var ans = new int[n, 2];
		for (int i = 0; i < n; i++)
		{
			string[] line = Console.ReadLine().Trim().Split(' ');
			ans[i, 0] = int.Parse(line[0]);
			ans[i, 1] = int.Parse(line[1]);
		}
		return ans;
	}
}



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

int main(){
    int A, B, ans = 0;
    cin >> A >> B;
    while(A <= B){
        if(A / 10000 == A % 10 && A / 1000 % 10 == A / 10 % 10){
            ans++;
        }
        A++;
    }
    cout << ans <<endl;
}

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

int main(void) {
    int A,B,C,X; cin>>A>>B>>C>>X;
    
    int counter = 0;
    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
                if (a*500 + b*100 + c*50 == X)
                    counter++;
                
            }
        }
    }
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double 
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define inf  1e18
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fi first
#define se second 
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    set<ll>s;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        s.insert(a[i]);
        auto itr=s.begin();
        if(*itr>=a[i])
        {
            ans++;
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	string A, B; 
	cin >> A >> B; 
	string ans = "EQUAL"; 
	if(A.size() > B.size()){ans = "GREATER";}
	else if(A.size() < B.size()){ans = "LESS";}
	else{
		int L = A.size(); 
		for(int i = 0; i < L; i++){
			if(A.at(i) > B.at(i)){
				ans = "GREATER"; break;}
			else if(A.at(i) < B.at(i)){
				ans = "LESS"; break;}
		} 
	}	
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int k, i, r;

    scanf("%d", &k);

    r = 0;
    for (i = 0; i < k; i++) {
        r = (r * 10 + 7) % k;
        if (r == 0) {
            printf("%d\n", i + 1);
            return 0;
        }
    }

    printf("-1\n");

    return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int n, m;
	cin >> n >> m;
	int* a = new int[n];
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	if (sum % (4 * m) == 0) {
		sum /= (4 * m);
	}
	else {
		sum /= (4 * m);
		++sum;
	}

	int num = 0;
	rep(i, n) {
		if (a[i] >= sum) ++num;
	}

	if (num >= m) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int b,c,n,m,i,j,k;

    scanf("%d",&n);
    unsigned long long a[10000];
    for(i=1;i<10000;i++)
    {
        a[i]=i;
    }
    a[0]=2;
    for(i=2;i<=n;i++)
    {
        a[i]=a[i-1]+a[i-2];
    }
    printf("%llu",a[n]);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>

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

int main()
{
	ll x; int k;
	cin>>x>>k;
	ll r[100001], ra[100001];
	r[0]=0; ra[0]=0;
	for(int i=1; i<=k; i++){
		cin>>r[i];
		if(i%2) ra[i]=ra[i-1]+r[i]-r[i-1];
		else ra[i]=ra[i-1]-r[i]+r[i-1];
	}
	int q;
	cin>>q;
	ll a[100000];
	ll t[100000];
	for(int i=0; i<q; i++){
		cin>>t[i]>>a[i];
	}
	ll x1=0, x2=x;
	ll ans0=-1;
	int j=0;
	for(int i=0; i<=k; i++){
		while(j<q && (i==k || t[j]<r[i+1])){
			ll t1=t[j]-r[i], ans;
			if(ans0>=0){
				if(i%2) ans=min(x, ans0+t1);
				else ans=max(0ll, ans0-t1);
			}else if(x1>a[j]){
				if(i%2) ans=min(x, x1-ra[i]+t1);
				else ans=max(0ll, x1-ra[i]-t1);
			}else if(x2<a[j]){
				if(i%2) ans=min(x, x2-ra[i]+t1);
				else ans=max(0ll, x2-ra[i]-t1);
			}else{
				if(i%2) ans=min(x, a[j]-ra[i]+t1);
				else ans=max(0ll, a[j]-ra[i]-t1);
			}
          cout<<ans<<endl;
			j++;
		}
		if(i==k) break;
		if(ans0>=0){
			if(i%2) ans0=min(x, ans0+r[i+1]-r[i]);
			else ans0=max(0ll, ans0-r[i+1]+r[i]);
		}else if(i%2){
			if(x+ra[i+1]<x2){
				x2=x+ra[i+1];
			}
			if(x1>=x2){
				ans0=x;
			}
		}else{
			if(ra[i+1]>x1){
				x1=ra[i+1];
			}
			if(x1>=x2){
				ans0=0;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 4352
// Try AtCoder
// author: Leonardoen @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut c = 1;
    let mut last = get!();
    let mut ans = 0;
    for _ in 1..n {
    	let x = get!();
        if x == last {
        	c += 1;
        } else {
        	ans += c / 2;
            c = 1;
            last = x;
        }
    }
    ans += c / 2;
    println!("{}", ans);
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	ll m = 100, cnt = 0;
	while (m < x) {
		m += m / 100;
		cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3568
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype=np.int64)

if np.sum([a < 0]) % 2 == 0 or np.sum([a == 0]) > 0:
    print(np.sum(np.abs(a)))
else:
    print(np.sum(np.abs(a)) - np.min(np.abs(a)) * 2)

Measured memory_bytes: 23308
#include <bits/stdc++.h> 
#define pb push_back
#define mp make_pair 
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
  
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
int main()
{
    int no_of_stones, no_of_steps;
    cin >> no_of_stones >> no_of_steps;

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    const int oo = 1e9;
    vector <int> minimum_cost(no_of_stones + 1, oo);
    minimum_cost[1] = 0;

    for(int i = 2; i <= no_of_stones; i++)
    {
        for(int j = i - 1; j >= max(1, i - no_of_steps); j--)
        {
            minimum_cost[i] = min(minimum_cost[i], minimum_cost[j] + abs(height[i] - height[j]));
        }
    }

    cout << minimum_cost[no_of_stones];
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    ll ans=0;
    Vec a(n);
    Vec b(n);
    Vec diff(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];

    deque<ll> q;
    rep(i,n){
        diff[i] = a[i]-b[i];
    }

    sort(ALL(diff));
    rep(i,n){
        q.push_front(diff[i]);
    }

    ll damage = 0;

    if(diff[0]>=0){
        cout <<0<<endl;
        return 0;
    }
    while(true){
        ll &back = q.back();
        if(back>=0){
            break;
        }
        damage += -back;
        ans ++;
        q.pop_back();
    }

    while(true){
        if(q.empty()){
            cout <<-1<<endl;
            return 0;
        }
        ll &front = q.front();
        damage -= front;
        ans ++;
        if(damage<0){
            break;
        }
        q.pop_front();
    }
    
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 3456
#define R(x)if(r>x)r=x;
main(r,D,a,b,c,d,e,A,B,C){for(;scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&A,&B,&C)>7;printf("%d\n",r)){
	if(C>=d){
		r=a*A+b*B+e*C;
	}else{
		r=a*A+b*B+c*C;
		R(a*A+b*B+e*d)
		if(B+C>=d){R(a*A+b*(B+C-d)+e*d)}
		else if(A+B+C>=d){R(a*(A+B+C-d)+e*d)}
		else{R(e*d)}
	}
}exit(0);}

Measured memory_bytes: 600
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int W, N, v, w;
    char c;
    int case_ = 0;

    while (cin >> W) {
        if (W == 0) break;
        cin >> N;
        case_++;

        int dp[N + 1][W + 1];
        fill(dp[0], dp[N + 1], 0);
        dp[0][0] = 0;

        for (int i = 0; i < N; i++) {
            cin >> v >> c >> w;
            for (int j = 0; j <= W; j++) {
                if (j < w) {
                    dp[i + 1][j] = dp[i][j];
                } else {
                    dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v);
                }
            }
        }

        int max_v = dp[N][W];
        int min_w;

        for (int i = W; i >= 0; i--) {
            if (dp[N][i] == max_v) min_w = i;
            else break;
        }

        cout << "Case " << case_ << ":" << endl;
        cout << max_v << endl;
        cout << min_w << endl;
    }
}


Measured memory_bytes: 6992