akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')

l = 0
r = n-1
ans = 0
while l < r:
    if s[l] == "W" and s[r] == "R":
        ans += 1
        l += 1
        r -= 1
    if s[l] == "R":
        l += 1
    if s[r] == "W":
        r -= 1

print(ans)


Measured memory_bytes: 67844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int m=n%10;
    if(m==2||m==4||m==5||m==7||m==9)
        cout<<"hon"<<endl;
    else if(m==0||m==1||m==6||m==8)
        cout<<"pon"<<endl;
    else
        cout<<"bon"<<endl;
}


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

int main() {
  long long int N;
  cin >> N;
  long long int ans=0;
  for(int i=1; i<=N; i++){
    if(i%3!=0 && i%5!=0)
      ans+=i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int main() {
  vector<string> s;
  string t;
  while(cin >> t) s.pb(t);
  int d[s.size()+2][s[1].size()*2+1];
  memset(d,0,sizeof(d));
  rep(i,s.size()) {
    rep(j,s[i].size()) {
      if(i%2) {
	d[i+1][j*2+1]=(s[i][j]=='1');
      } else {
	d[i+1][j*2+2]=(s[i][j]=='1');
      }
    }
  }
  string ans="";
  int x=1,y=1,z=0;
  char c[4]={'U','R','D','L'};
  for(int i=0; i<4; i++) {
    int k=(z+3)%4;
    int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
    if(d[nx][ny]==1) {
      x+=dx[(i+k)%4]*2;
      y+=dy[(i+k)%4]*2;
      ans+=c[(i+k)%4];
      z=(i+k)%4;
      break;
    }
  }
  while(x!=1 || y!=1) {
    for(int i=0; i<4; i++) {
      int k=(z+3)%4;
      int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
      if(d[nx][ny]==1) {
	x+=dx[(i+k)%4]*2;
	y+=dy[(i+k)%4]*2;
	ans+=c[(i+k)%4];
	z=(i+k)%4;
	break;
      }
    }
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 1196
# AOJ 0062: What is the Bottommost?
# Python3 2018.6.15 bal4u

while True:
	try:
		a = list(map(int, input()))
	except EOFError:
		break

	for i in range(9, 0, -1):
		for j in range(1, i+1):	a[j-1] = (a[j-1]+a[j]) % 10
	print(a[0])


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {

	in(ll, X, Y);
	out(X + Y / 2);

	return 0;
}


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

const ll MAX = 1000005;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, ans=0, tmp=0;
vector<ll> A, Nums;
string S;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

signed main() {
    cin >> N;
    Nums.resize(MAX, 0);
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
        Nums[a]++;
        tmp += a;
    }
	for(int i=2;i<=1000000;i++) {
		int x=0;
		for(int j=i;j<=1000000;j+=i) x+=Nums[j];
		if(x>=2) break;
        if(i==1000000) {
            cout<<"pairwise coprime"<<endl;
            return 0;
        }
	}	
    tmp = A[0];
    for(int i=1;i<N;i++) {
        tmp = GCD(tmp, A[i]);
    }
    if(tmp==1) {
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 19384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, K; cin >> A >> B >> K;

    vi ans;    
    for(int i=A; i<=B; i++) {
        if (i-A+1 <=K || B-i+1 <=K) {
            ans.push_back(i);
        }
    }

    for(int i : ans) cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
from math import gcd

N,*A = map(int, open(0).read().split())
m = max(A)
if m == 1:
    print('pairwise coprime')
else:
    minfactor = [-1] * (m+1)
    for i in range(2,m+1):
        if minfactor[i] == -1:
            for j in range(1,m//i+1):
                minfactor[i*j] = i
    temp = gcd(A[0],A[1])
    for i in range(2,N):
        temp = gcd(temp,A[i])
        if temp == 1:
            break
    if temp > 1:
        print('not coprime')
    else:
        s = set()
        for x in A:
            if x > 1:
                p = x
                while p > 1:
                    mf = minfactor[p]
                    if mf not in s:
                        s.add(mf)
                        while p % mf == 0:
                            p = p // mf
                    else:
                        break
                else:
                    continue
                print('setwise coprime')
                break
        else:
            print('pairwise coprime')

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

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	string N;
	cin >>N;
	int S=0;
	Rep0(i, 4)
		if ('2'==N.at(i))
			S++;
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int tmp = K;
    while(K <= B) {
        if(A <= K) {
            cout << "OK";
            return 0;
        }
        K += tmp;
    }
    cout << "NG";
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int dis( P p , P p_ ){
	return abs(p.first-p_.first)+abs(p.second-p_.second);
}

int to_i(string s){
	int n=0;
	for(int i=0 ; i < s.size() ; i++ ){
		n = n*10 + s[i]-'0';
	}
	return n;
}

int main(){
	int w,h;
	while( cin >> w >> h , w||h ){
		string s;
		map<int,vector<P> > f;
		vector< vector<int> > dp;
		int gx,gy,t=0;

		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> s;
				if( s == "S" ){
					vector<int> vc;
					vc.push_back( 0 );
					dp.push_back( vc );
					P p(x,y);
					f[0].push_back( p );
				}else if( s == "G" ){
					gx = x;
					gy = y;
				}else if( s != "." ){
					int n = to_i(s);
					t = max( t , n );
					P p(x,y);
					f[n].push_back( p );
				}
			}
		}
		P p(gx,gy);
		f[t+1].push_back( p );
		for(int i=1 ; i <= t+1 ; i++ ){
			vector<int> vc;
			for(int j=0 ; j < f[i].size() ; j++ ){
				vc.push_back( 1000000 );
			}
			dp.push_back( vc );
		}
		for(int i=0 ; i <= t ; i++ ){
			for(int j=0 ; j < f[i].size() ; j++ ){
				for(int k=0 ; k < f[i+1].size() ; k++ ){
					int d = dis( f[i+1][k] , f[i][j] );
					dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+d );
				}
			}
		}
		cout << dp[t+1][0] << endl;
	}
}

Measured memory_bytes: 1192
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
string t;
signed main() {
	int n, k;
	cin >> n >> k;
	int a, b, c;
	cin >> a >> b >> c;
	string s;
	cin >> s;
	int ans = 0;
	rep(i, n) {
		if (s[i] == 'r') {
			if (i - k >= 0) {
				if (t[i - k] == 'p') {
					t+= 'x';
				}
				else {
					t+= 'p';
					ans += c;
				}
			}
			else {
				t+= 'p';
				ans += c;
			}
		}
		if (s[i] == 's') {
			if (i - k >= 0) {
				if (t[i - k] == 'r') {
					t+= 'x';
				}
				else {
					t+= 'r';
					ans += a;
				}
			}
			else {
				t+= 'r';
				ans += a;
			}
		}
		if (s[i] == 'p') {
			if (i - k >= 0) {
				if (t[i - k] == 's') {
					t+= 'x';
				}
				else {
					t+= 's';
					ans += b;
				}
			}
			else {
				t+= 's';
				ans += b;
			}
		}
	}
	cout << ans << endl;
}


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

int main(void) {
  int N;
  string S, T;
  cin >> N >> S >> T;
  for (int i = 0; i < 2 * N; i++) {
    cout << (i % 2 == 0 ? S[i / 2] : T[i / 2]);
  }
  cout << endl;
  return 0;
}

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

int get(){
    int ret=0;
    for(int i=0;i<4;i++){
        int a;cin>>a;
        ret+=a;
    }
    return ret;
}
int main(){
    cout<<max(get(),get())<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
	while(true){
		int n;
		cin >>n;
		if(n==0)
			break;

		int pm,pe,pj;
		for(int i=0 ;i<n ;i++){
			cin >> pm >> pe >> pj;
	
			if(pm == 100 || pe == 100 || pj == 100)
				cout << 'A' << endl;
			else if((pm + pe) / 2 >=90)
				cout << 'A' << endl;
			else if((pm+pe+pj) / 3 >=80)
				cout << 'A' << endl;
			else if((pm+pe+pj) /3 >=70)
				cout << 'B' << endl;
			else if((pm>=80 ||pe>=80) &&(pm+pe+pj) / 3 >=50)
				cout << 'B' << endl;
			else
				cout << 'C' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r, d, x;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        int cur;
        cur = r*x - d;
        cout << cur << "\n";
        x = cur;
    }
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    input!(h, w, a: [chars; h]);
    for i in 0..h {
        println!(
            "{}",
            (0..w)
                .map(|j| if j == 0 || i % 2 == 0 && j + 1 < w || a[i][j] == '#' {
                    '#'
                } else {
                    '.'
                })
                .collect::<String>()
        );
    }
    println!("");
    for i in 0..h {
        println!(
            "{}",
            (0..w)
                .map(
                    |j| if j + 1 == w || i % 2 == 1 && j != 0 || a[i][j] == '#' {
                        '#'
                    } else {
                        '.'
                    }
                )
                .collect::<String>()
        );
    }
}


Measured memory_bytes: 4860
n = list(raw_input())
op = ['+', '-']

for o1 in op:
  for o2 in op:
    for o3 in op:
      s = n[0] + o1 + n[1] + o2 + n[2] + o3 + n[3]
      if eval(s) == 7:
        print s + '=7'
        exit(0)



Measured memory_bytes: 2568
#include <bits//stdc++.h>
using namespace std;
int in(void){int x;cin>>x;return x;}
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define ll long long int
long long int dx[4]={1,0,-1,0};
long long int dy[4]={0,1,0,-1};
int D[2]={1,-1};
int main() {
  int h,w;
  int y,x;
  cin>>h>>w>>y>>x;
  int num=h*w;
  cout<<num-(h*x+w*y-x*y);
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int cif(int i){
    int cnt = 0;
    while(i>0){
        i /= 10;
        ++cnt;
    }
    return cnt;
}

int main(){
    int n, m;
    cin >> n >> m;
    int p[100005]={}, y[100005]={}, r[100005]={}, cnt[100005]={};
    pair<pair<int, int>, int> pa[100005];
    rep(i, m){
        cin >> p[i] >> y[i];
        pa[i].first.first = p[i];
        pa[i].first.second = y[i];
        pa[i].second = i;
    }
    sort(pa, pa+m);
    rep(i, m){
        ++r[pa[i].first.first];
        cnt[pa[i].second] = r[pa[i].first.first];
    }

    rep(i, m){
        rep(k, 6-cif(p[i]))cout << 0;
        cout << p[i];
        int j = cif(cnt[i]);
        rep(k, 6-j)cout << 0;
        cout << cnt[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var s = ReadLine();
        var apos = 0;
        var zpos = 0;
        for (var i = 0; i < s.Length; i++)
        {
            if (s[i] == 'A')
            {
                apos = i;
                break;
            }
        }
        for (var i = s.Length-1; i > 0; i--)
        {
            if (s[i] == 'Z')
            {
                zpos = i;
                break;
            }
        }
        WriteLine(zpos-apos+1);
    
    }
}



Measured memory_bytes: 3416
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc =  new Scanner(System.in);
		//money:お金
		long money = 1000;
		//stock:株
		long stock = 0;
		//N:期間
		int n = Integer.parseInt(sc.next());
		//各日の株予想
		long[] longArr = new long[n];
		for (int i=0; i<n; i++) {
			longArr[i] = Long.parseLong(sc.next());
		}
		
		for (int i=0; i<n-1; i++) {
			//case : 株を買う->底値の時
			if(longArr[i] < longArr[i+1] ) {
				stock = money / longArr[i];
				money += (longArr[i+1] - longArr[i])*stock;
			}
		}
		System.out.println(money);
	}
}


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

int main(){
  string s; cin >> s;
  for(int i=0; i<s.size()-1; i++){
    if(s.substr(i, 2) == "AC"){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))

total=0
for i in range(N):
    total+=A[i]

count=0
for i in range(N):
    if A[i]*4*M>=total:
        count+=1

if count>=M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');
static int n = int.Parse(input[0]);
static int q = int.Parse(input[1]);
static int[] unionfind = new int[n];//親

	static void Main()
	{  
    for(int i = 0; i < n; i++)
    {
      unionfind[i] = -1;//初期化
    }
    
    for(long i = 0; i < q; i++)
    {
      int[] numsa = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      
      if(numsa[0] == 0) UnionFindUnite(numsa[1],numsa[2]);//結合
      else
      {
        if(UnionFindFind(numsa[1]) == UnionFindFind(numsa[2])) Console.WriteLine(1);
        else Console.WriteLine(0);
      }
    }
	}

  static void UnionFindUnite(int x, int y)
  {//unionfindで頂点x,yをO(log頂点数)で結合
    x = UnionFindFind(x);
    y = UnionFindFind(y);
    if(x == y) return;

    if(unionfind[x] > unionfind[y])
    {
      int swapMemo = unionfind[x];
      unionfind[x] = unionfind[y];
      unionfind[y] = swapMemo;
    }
    unionfind[x] += unionfind[y];
    unionfind[y] = x;
  }

  static int UnionFindFind(int x)
  {//unionfindで頂点xが属する集合をO(log頂点数)で返す
    if(unionfind[x] < 0) return x;
    return (unionfind[x] = UnionFindFind(unionfind[x]));
  }

  static int UnionFindSize(int x)
  {//unionfindで頂点xが属する集合の大きさをO(log頂点数)で返す
    return (-unionfind[UnionFindFind(x)]);
  }

  static int[] UnionFindSizes()
  {//unionfindで各集合の大きさをO(頂点数 *log頂点数)で返す
  //例えば{1,2,5,2}なら{1,2,1}(順不同)を返す
    int[] answers;
    int answerCount = 1;
    int answerCountSub = 0;
    int n = unionfind.Length;
    int[] parents = new int[n];
    for(int i = 0; i < n; i++)
    {
      parents[i] = UnionFindFind(i);
    }
    Array.Sort(parents);

    for(int i = 1; i < n; i++)
    {
      if(parents[i-1] != parents[i]) answerCount++;
    }
    answers = new int[answerCount];
    answers[0]++;

    for(int i = 1; i < n; i++)
    {
      if(parents[i-1] != parents[i])
      {
        answerCountSub++;
      }
      answers[answerCountSub]++;
    }
    
    return answers;
  }
  
}


Measured memory_bytes: 22176
#include<cstdio>
#include<vector>
#include<stack>
#include<utility>

using namespace std;


int getLargestRectangle(vector<int>& H) {
  stack<pair<int, int> > S;
  int maxv = 0;
  H.push_back(0);

  for (size_t i = 0; i < H.size(); ++i) {
    pair<int, int> rect = make_pair(H[i], i);
    if (S.empty()) {
      S.push(rect);
    } else {
      if (S.top().first < rect.first)
        S.push(rect);
      else if (S.top().first > rect.first) {
        int target = i;
        while (!S.empty() && S.top().first >= rect.first) {
          pair<int, int> pre = S.top(); S.pop();
          int area = pre.first * (i - pre.second);
          maxv = max(maxv, area);
          target = pre.second;
        }
        rect.second = target;
        S.push(rect);
      }
    }
  }
  return maxv;
}


int getLargestRectangle(int h, int w, const vector<vector<bool> >& g) {
  vector<vector<int> > dp(h, vector<int>(w, 0));

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (g[i][j]) dp[i][j] = 0;
      else {
        dp[i][j] = (i > 0) ? dp[i-1][j]+1 : 1;
      }
    }
  }

  int maxv = 0;
  for (int i = 0; i < h; ++i) {
    maxv = max(maxv, getLargestRectangle(dp[i]));
  }

  return maxv;
}

void solve(int h, int w) {
  vector<vector<bool> > g(h, vector<bool>(w, false));

  for (int i = 0 ; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      int p;
      scanf("%d", &p);
      g[i][j] = p == 1;
    }

  printf("%d\n", getLargestRectangle(h, w, g));
}

int main() {

  int h, w;
  scanf("%d %d", &h, &w);
  
  solve(h, w);
  return 0;
}



Measured memory_bytes: 16904
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

int main() {

    LL N;
    cin >> N;

    vector<LL> P(N);
    for (int i = 0; i < N; i++) cin >> P[i];

    vector<pair<LL, LL>> A(N);
    for (int i = 0; i < N; i++) A[i] = make_pair(P[i], i);
    sort(A.rbegin(), A.rend());

    multiset<int> st;
    st.insert(A[0].second);
    st.insert(-1);
    st.insert(N);
    st.insert(-1);
    st.insert(N);

    LL ans = 0;
    for (int i = 1; i < N; i++) {
        LL val = A[i].first;
        LL pos = A[i].second;

        st.insert(pos);

        auto l_pos = st.lower_bound(pos);
        auto r_pos = st.lower_bound(pos);
        l_pos--;
        r_pos++;
        auto ll_pos = l_pos;
        auto rr_pos = r_pos;
        ll_pos--;
        rr_pos++;
        LL d = 0;
        d += (*l_pos - *ll_pos) * (*r_pos - pos);
        d += (*rr_pos - *r_pos) * (pos - *l_pos);
        ans += d * val;
    }

    cout << ans << endl;

}






























































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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  ll H, W;
  std::cin >> H >> W;

  if(H == 1 || W == 1) {
    std::cout << 1 << '\n';
    return 0;
  }

  std::cout << (H * W + 1) / 2LL << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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

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


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ac = a * c;
	ll ad = a * d;
	ll bc = b * c;
	ll bd = b * d;
	cout << max(max(ac, ad), max(bc, bd)) << endl;
	return 0;
}


Measured memory_bytes: 3620
def generate(len, origin):
    lis = []
    for i in range(len):
        if i % 2 == 0:
            lis.append(origin)
        else:
            lis.append(abs(origin - 1))
    return lis

a = list(map(int, list(input())))
data = list(a)
origin = a[0]
risou = generate(len(data), origin)
res = 0

for i in range(len(data)):
    if data[i] != risou[i]:
        res = res + 1
print(res)


Measured memory_bytes: 5528
package main

import (
	"container/heap"
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			if i < j {
				g[i][j] = max(0, as[j]-as[i])
			}
		}
	}

	ds := dijkstra(g)

	money := 1000
	for i := 0; i < n-1; i++ {
		if ds[i] < ds[i+1] {
			c := money / as[i]
			money -= as[i] * c
			money += as[i+1] * c
		}
	}

	fmt.Println(money)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

const inf int = 1e9

var prev = [10]int{}

func dijkstra(g [][]int) []int {
	n := len(g)
	dist := make([]int, n)
	for i := 1; i < n; i++ {
		dist[i] = -inf
	}

	var pq PriorityQueue
	heap.Init(&pq)

	heap.Push(&pq, &Item{pos: 0, cost: 0})
	dist[0] = 0

	for len(pq) > 0 {
		c := heap.Pop(&pq).(*Item)
		if dist[c.pos] > c.cost {
			continue
		}

		for v := c.pos + 1; v < n; v++ {
			cost := g[c.pos][v]
			if dist[v] < c.cost+cost {
				dist[v] = c.cost + cost
				heap.Push(&pq, &Item{pos: v, cost: dist[v]})
			}
		}
	}

	return dist
}

// Item .
type Item struct {
	pos   int
	cost  int
	index int
}

// PriorityQueue .
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].cost > pq[j].cost
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

// Push .
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

// Pop .
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;


int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int h,n;
	cin>>h>>n;
	vector<int> dp(h+1,INF);
	dp[0]=0;
	for(int sp=0;sp<n;++sp){
		int val,cost;
		cin>>val>>cost;
		for(int i=0;i<=h;++i){
			int hp=min(h,i+val);
			dp[hp]=min(dp[hp],dp[i]+cost);
		}
	}
	cout<<dp[h];	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define rawan ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define ll long long
using namespace std;
const int N = 1e5 + 5;
int main()
{rawan;
int n;
cin >> n;
int a[n],b[n],c[n];
for (int i=0; i<n; i++)
{
    cin >> a[i] >> b[i] >> c[i];
}
int dp[n][4]={};
dp[0][0]=a[0], dp[0][1]=b[0], dp[0][2]=c[0];
for (int i=1; i<n; i++)
{
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
}
cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
    return 0;
}


Measured memory_bytes: 2944
list = [int(input()) for _ in range(5)]
list_diff = []

for i in list:
    if i%10 == 0:
        list_diff.append([0,i,i])
    else:
        list_diff.append([10-i%10,i,10*(i//10+1)])

list_diff.sort()
ans = 0

for i in range(5):
    if i == 4:
        ans += list_diff[i][1]
    else:
        ans += list_diff[i][2]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll h,w,n ;
	cin >> h >> w >> n ;
	vector<pll> a(n) ;
	set<pll> s ;
	for(int i=0;i<n;i++){
		cin >> a.at(i).first >> a.at(i).second ;
		s.insert({a.at(i).first,a.at(i).second}) ;
	}
	vll ans(10,0) ;
	set<pll> use ;
	for(int i=0;i<n;i++){
		ll y = a.at(i).first ;
		ll x = a.at(i).second ;
		for(int j=-2;j<=0;j++){
			for(int k=-2;k<=0;k++){
				if(y+j<=0||y+j+2>h||x+k<=0||x+k+2>w) continue ;
				if(use.count({y+j,x+k})) continue ;
				ll cnt = 0 ;
				for(int l=0;l<3;l++){
					for(int m=0;m<3;m++){
						if(s.count({y+j+l,x+k+m})) cnt++ ;
					}
				}
				ans.at(cnt)++ ;
				use.insert({y+j,x+k}) ;
			}
		}
	}
	ll sum = 0 ;
	for(int i=1;i<10;i++) sum += ans.at(i) ;
	ans.at(0) = (h-2)*(w-2)-sum ;
	for(auto i:ans) cout << i << endl ;
}


Measured memory_bytes: 64256
from collections import deque

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

G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
# print(G)

todo = deque()
seen = set()

todo.append(0)
seen.add(0)

ans = [-1 for _ in range(N)]
while len(todo) > 0:
    here = todo.popleft()
    for neighbor in G[here]:
        if neighbor not in seen:
            todo.append(neighbor)
            seen.add(neighbor)
            if ans[neighbor] == -1:
                ans[neighbor] = here

print("Yes")
for i in range(1, N):
    print(ans[i]+1)



Measured memory_bytes: 107196
#include<iostream>
#include<string>
int main(){
  int length = 0;
  int flg = 0;
  unsigned char inX[110];
  std::cin >> inX;
  for(unsigned char i = 0;i < 105;i++){
    if(inX[i] == 0){
      length = i;
      break;
    }
  }
  for(int i = 0; i < length / 2;i++){
    if(inX[i] != inX[length - 1 - i]){
      flg++;
    }
  }
  std::cout << flg;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
//import javafx.util.Pair;
public class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		FastReader sc = new FastReader();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scn = new Scanner(System.in);
		
//	Vector<Vector<IntegerPai>>adj=new Vector<>();
String s=sc.next();
int w=0,l=0;
for(int i=0;i<s.length();i++)
{
	if(s.charAt(i)=='o')
		w++;
	else
		l++;
	}
	  w=w+(15-(l+w));
	  if(w>=8)
	  {
		  System.out.println("YES");
	  }
	  else
		  System.out.println("NO");
	}}


Measured memory_bytes: 23508
using System;
using System.Collections.Generic;
using System.Linq;
class P{
  static void Main(){
    string[] s = Console.ReadLine().Split();
    int n = int.Parse(s[0]);
    int k = int.Parse(s[1]);
    int[] h = new int[n];
    for (int i = 0;i < n;i++)
      h[i] = int.Parse(Console.ReadLine());
    Array.Sort(h);
    List<int> l = new List<int>();
    for (int i = 0;i <= n - k;i++)
      l.Add(h[i + k - 1] - h[i]);
    Console.WriteLine(l.Min());
  }
}

Measured memory_bytes: 17756
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
	int n,t,c;
	int mid,high,low,key;
	vector<int> d;
	while(cin >> n && n){
		d.clear();c=0;
 
		for(int i=0;i<n;i++){
			cin >> t;
			d.push_back(t);
		}
 
		cin >> key;
		low=0;high=n-1;	
		do{
			mid=(low+high)/2;
 
			if(d[mid] < key)
				low = mid+1;
			else if(d[mid] > key)
				high = mid-1;
			c++;
		}while(key != d[mid] && mid !=high && mid !=low);
 
		cout << c << endl;
	}
}

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

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

Measured memory_bytes: 1792
n,k = map(int,input().split())
s = input()
I  = [0]
for i in range(1,n):
    if s[i-1] != s[i]:
        I.append(i)
I.append(n)
r = len(I)-1
X = []
for i in range(r):
    if s[I[i]] == "0":
        X.append(I[min(2*k+i,r)]-I[i])
    else:
        X.append(I[min(2*k+1+i,r)]-I[i])
print(max(X))

Measured memory_bytes: 16976
#include <bits/stdc++.h>
using namespace std;
int N; 
int A[200010], B[200010]; 
long long Pow[200010]; 
pair<int, int> P[200010];
set<int> S;
map<int, int> M;
long long mod = 998244353; 
void add(int a, int b){
	int x = a; 
	while(x <= N){
		B[x] += b; x += x & -x; 
	}
}
int sum(int a){
	int res = 0; 
	int x = a; 
	while(x > 0){
		res += B[x]; x -= x & -x;
	}
	return res; 
}
int main(){
	Pow[0] = 1; 
	for(int i = 1; i <= 200005; i++) Pow[i] = Pow[i-1] * 2 % mod;
	cin >> N; 
	for(int i = 1; i <= N; i++){
		cin >> P[i].first >> P[i].second;
		S.insert(P[i].second); 
	}
	sort(P+1, P+N+1); 
	int it = 0; 
	for(auto i = S.begin(); i != S.end(); i++){
		M[*i] = ++it;
	}
	for(int i = 1; i <= N; i++){
		A[i] = M[P[i].second]; 
	}
	long long all = Pow[N] * N % mod; 
	long long impo = 0;
	for(int i = 1; i <= N; i++){
		int bottom = A[i] - 1;
		int left = i - 1;  
		int BL = sum(A[i]); 
		int BR = bottom - BL; 
		int TL = left - BL; 
		int TR = N - 1 - BL - BR - TL; 
		add(A[i], 1); 
		long long tmp = 0; 
		tmp += Pow[BL + BR] + Pow[BR + TR] + Pow[TR + TL] + Pow[TL + BL]; 
		tmp += mod * 4 - Pow[BL] - Pow[BR] - Pow[TL] - Pow[TR] + 1; 
		impo += tmp; impo %= mod; 
	} 	
	cout << (mod + all - impo) % mod << endl;
}

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


void solve(long long a, long long b){
    string aa = to_string(a);
    for(int i = 0; i < b-1; ++i){
        aa = aa + to_string(a);
    }
    string bb = to_string(b);
    for(int i = 0; i < a-1; ++i){
        bb = bb + to_string(b);
    }
    cout << min(aa, bb) << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

ll inp[1005][3];

int main(){
    int n, m;
    fastScan(n); fastScan(m);
    for(int i = 0; i < n; i++){
        fastScan(inp[i][0]);
        fastScan(inp[i][1]);
        fastScan(inp[i][2]);
    }
    ll ans = 0;
    for(int i = 0; i < 8; i++){
        vector < ll > vec(n);
        for(int j = 0; j < n; j++){
            ll cnt = 0;
            for(int k = 0; k < 3; k++){
                if(i & (1 << k)){
                    cnt += inp[j][k];
                } else {
                    cnt -= inp[j][k];
                }
            }
            vec[j] = cnt;
        }
        sort(vec.rbegin(), vec.rend());
        ll tmp = 0;
        for(int j = 0; j < m; j++){
            tmp += vec[j];
        }
        if(tmp > ans) ans = tmp;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
import itertools

n=[x for x in range(1,int(input())+1)]
P=list(map(int, input().split()))
Q=list(map(int, input().split()))

for i, a in enumerate(itertools.permutations(n), start=1):
  if list(a)==P:
    p=i
  if list(a)==Q:
    q=i
print(abs(p-q))


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


int main() {
  
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    if (h >= K) ans++;
  }
  
  cout << ans << endl;
  
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1;
  int y = y2 - y1;
  int x3 = x2 + -y;
  int y3 = y2 + x;
  int x4 = x3 - x;
  int y4 = y3 - y;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

// mod付きpower
// x^n
ll modpow(ll x, int n) {
	if (n == 0) return 1LL;
	else if (n % 2 == 0) return modpow((x * x) % MOD, n / 2) % MOD;
	else return (modpow((x * x) % MOD, n / 2) * x) % MOD;
}

// a/bを返す
ll divMod(ll a, ll b) {
	ll res = a * modpow(b, MOD - 2);
	return res % MOD;
}



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

	ll n, a, b; cin >> n >> a >> b;
	ll ans = modpow(2LL, n);
	ans--;

	ll num1 = 1, num2 = 1;
	for (ll i = n; i >= n - a + 1; i--) num1 = (num1 * i) % MOD;
	for (ll i = 1; i <= a; i++) num1 = divMod(num1, i);
	for (ll i = n; i >= n - b + 1; i--) num2 = (num2 * i) % MOD;
	for (ll i = 1; i <= b; i++) num2 = divMod(num2, i);

	cout << (ans + MOD + MOD - num1 - num2) % MOD << endl;

	return 0;
}

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


// returns min(x : where As[i:i+x) contains all the elements of [1..K])
int smallest_window(int K, vector<int> As){
    vector<int> freq(K + 1, 0);
    int t = K;
    int record = As.size() + 10;
    int tail = 0;
    for (int head = 0; head < As.size(); ++head){
        while (tail < As.size() and t > 0){
            int a = As[tail];
            if (1 <= a and a <= K){
                ++freq[a];
                if (freq[a] == 1) --t;
            }
            ++tail;
        }
        if (t == 0 and tail - head < record) record = tail - head;
        int a = As[head];
        if (1 <= a and a <= K){
            --freq[a];
            if (freq[a] == 0) ++t;
        }
    }
    if (record > As.size()) return 0;
    return record;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> As(N);
    for (auto & a : As) cin >> a;
    cout << smallest_window(K, As) << endl;
    return 0;
}

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

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

	int			sum;
	int			min1;
	int			min1_i;
	vector<int> v(5);

	sum = 0;
	min1 = 9;
	min1_i = 0;
	rep(i, 5)
	{
		int n;

		cin >> n;
		v.at(i) = n;
		sum += ceil(n / 10.0) * 10;
		if (n % 10 != 0 && n % 10 < min1)
		{
			min1 = n % 10;
			min1_i = i;
		}
	}
	sum -= ceil(v.at(min1_i) / 10.0) * 10;
	sum += v.at(min1_i);
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int c[3][3];
int a[3],b[3];
int main(){
	REP(i,3) {
		REP(j,3) {
			cin >> c[i][j];
		}
	}

	for(a[0] = -100;a[0] < 101;a[0]++) {
		for(a[1] = -100;a[1] < 101;a[1]++) {
			for(a[2] = -100;a[2] < 101;a[2]++) {
				b[0] = c[0][0] - a[0];
				b[1] = c[1][1] - a[1];
				b[2] = c[2][2] - a[2];

				bool f = true;
				REP(i,3) {
					REP(j,3) {
						if(c[i][j] != a[i] + b[j]) {
							f = false;
						}
					}
				}
				if(f) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;
int main() {
	vector<int> s;
	vector<int> k;
	for (int j = 1; true; ++j) {
		int x = j * (j + 1) * (j + 2) / 6;
		s.push_back(x);
		if (x % 2 == 1) k.push_back(x);
		if (x > 1000000) break;
	}
	vector<pair<int, int>> res;
	vector<pair<int, int>> ans;
	unordered_map<int, int> idx;
	list<int> q1;
	list<int> q2;	
	for(int i = 1; true; ++i) {
		int c; 
		cin >> c;
		if (c == 0) break;
		q1.push_back(c);
		q2.push_back(c);
		idx.insert(pair<int, int>(c, i));
	}
	res.resize(idx.size());
	bitset<1000001> b;
	b[0] = true;
	for (int i = 1; !q1.empty(); ++i) {
		bitset<1000001> buf = b;
		for (int j : s) buf |= (b << j);
		for (auto it = q1.begin(); it != q1.end();) {
			if (buf[*it]) {
				res[idx[*it]-1].first = i;
				it = q1.erase(it);
			}
			else it++;
		}
		b = buf;
	}
	b.reset();
	b[0] = true;
	for (int i = 1; !q2.empty(); ++i) {
		bitset<1000001> buf = b;
		for (int j : k) buf |= (b << j);
		for (auto it = q2.begin(); it != q2.end();) {
			if (buf[*it]) {
				res[idx[*it]-1].second = i;
				it = q2.erase(it);
			}
			else it++;
		}
		b = buf;
	}
	rep(i, res.size()) cout << res[i].first << " " << res[i].second << endl;
	return 0;
}



Measured memory_bytes: 3612