akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve{
public:
    void input(){

    }
    void solve(){
        input();

        int n;
        cin >> n;
        vector<int> x(n);
        rep(i,0,n) cin >> x[i];
        sort(all(x));
        int ans = 0;
        for(int i = 0; i < n; ++i){
            ans += x[i];
        }
        
        ans -= x.back() / 2;
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n; cin >> n;
    bool flg = true;
    vector<int> a(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] % 2) flg = false;
    }

    if (flg) {
        int cnt = 0;
        while (flg) {
            for (int i = 0; i < a.size(); ++i) {
                a[i] /= 2;
                if (a[i] % 2) flg = false;
            }
            cnt++;
        }
        cout << cnt << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int dp[n];
  rep(i, n) dp[i] = INF;
  dp[n - 1] = 0;
  // dp[n - 2] = abs(h[n - 1] - h[n - 2]);
  repr(i, n - 1) {
    repi(j, 1, k + 1) {
      if (i + j > n - 1) continue;
      dp[i] = min(dp[i], abs(h[i] - h[i + j]) + dp[i + j]);
    }
  }
  cout << dp[0] << endl;
  return 0;
}


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

int main() {
  int e;
  while ( cin >> e && e ) {
    int answer = e;
    int l1 = (int)ceil(pow( e, 1.0/2.0 ));
    int l2 = (int)ceil(pow( e, 1.0/3.0 ));
    for ( int i = 0; i <= l1; i++ ) {
      for ( int j = 0; j <= l2; j++ ) {
	if ( i*i + j*j*j <= e ) {
	  int x = e - i * i - j * j * j;
	  int y = i;
	  int z = j;
	  answer = min( answer, x+y+z  );
	}
      }
    }
    cout << answer << endl;
  }
}

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


using namespace std;

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i < a + 1; ++i) {
        for (int j = 0; j < b + 1; ++j) {
            for (int k = 0; k < c + 1; ++k) {
                if (500 * i + 100 * j + 50 * k == x) ++ans;
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	ans += min(a,k);
	k -= min(a,k);
	if(k > 0){
		k -= min(b,k);
	} 
	if(k > 0){
		ans -= min(c,k);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);

    for (auto &&i : a)
    {
        cin >> i;
    }

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void){
	int A,B,C,D;
	scanf("%d %d %d",&A,&B,&C);
	D = A - (B + C);
	if(D > 0){
		D = 0;
	} else {
		D = abs(D);
	}
	printf("%d\n",D);
	return 0;
}

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

int main() {
	string s,t;
	cin>>s>>t;
	int min_dif = t.length();
	int s_len = s.length(), t_len = t.length();
	for(int i=0;i<=(s_len - t_len);i++) {
		int dif = 0;
		for(int j=0; j < t_len; j++) {
			if(s[i+j] != t[j]) dif++;
		}
		if(dif < min_dif) min_dif = dif;
	}
	cout<<min_dif<<"\n";
	return 0;
}

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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    int be = 0, af = 0;
    
    rep(i, m) {
        if (a[i] < x) {
            be++;
        }
        else if (a[i] > x) {
            af++;
        }
    }
    
    cout << min(be, af) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := nextInt(), nextInt()

	fmt.Printf("%d\n", ABC046B(N, K))
}

// ABC046B ...
func ABC046B(N, K int) int {
	return K * int(math.Pow(float64(K-1), float64(N-1)))
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//const ll MOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};


void solve(int ca){
    int N,K; cin>>N>>K;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int ans = 0;
    for (int i = 0; i < K; ++i) {
        ans+=a[i];
    }
    cout<<ans<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#define m 1000000007LL
using namespace std;
typedef long long ll;
int n;
string x[1001];
vector <int> G[1001];
ll SUM,R[11];

void saiki2(int ima,ll sum){
  if(ima==-1)return;
  for(int i=ima-1;i>=0;i--) saiki2(i,sum*R[i]);
  SUM+=sum;
}

ll saiki(int ima){
  ll S=G[ima].size(),res=1,r[11];
  for(int i=0;i<S;i++)r[i]=saiki(G[ima][i]);
  
  if(x[ima][0]=='E')
    for(int i=0;i<S;i++) res*=r[i];
  
  if(x[ima][0]=='A'){
    res=0;
    for(int i=0;i<S;i++) res+=r[i];
  }
  if(x[ima][0]=='R'){
    SUM=0;
    for(int i=0;i<S;i++) R[i]=r[i];
    saiki2(S,1);
    res=SUM-1;
  }
  return (res+x[ima].size()-1)%m;
}

int main(){
  cin >>n;
  for(int i=1;i<=n;i++)cin>>x[i];
  for(int i=1;i<n;i++){
    int a,b;
    cin >>a>>b;
    G[a].push_back(b);
  }
  cout <<saiki(1)<<endl;
  return 0;
}

Measured memory_bytes: 1444
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	for (a = 1; a <= 9; a++) {
		for (b = 1; b <= 9; b++) {
			printf("%dx%d=%d\n", a, b, a * b);
		}
	}
	return (0);
}	

Measured memory_bytes: 524
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] A1 = new int[N+1], A2 = new int[N+1];
		for(int i = 1;i < N+1;i++) {
			A1[i] = A1[i-1] + scn.nextInt();
		}
		for(int i = 1;i < N+1;i++) {
			A2[i] = A2[i-1] + scn.nextInt();
		}
		int ans = 0;
		for(int i = 0;i < N;i++) {
			ans = Math.max(ans, A1[i+1] - A1[0] + A2[N] - A2[i]);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val xList = readLine()?.split(" ")?.map { Integer.parseInt(it) } ?: return

    val middleIndex = n / 2
    val sortedX = xList.sorted()

    val middleValue = sortedX[middleIndex] // 真っ二つにしたときに、大きい方の1番目に該当する値
    val lessMiddleValue = sortedX[middleIndex - 1] // 真っ二つにしたときに、小さい方のlastに該当する値

    val resultStr = xList.map {
        if (it >= middleValue) {
            lessMiddleValue
        } else {
            middleValue
        }
    }.joinToString("\n")

    println(resultStr)
}

Measured memory_bytes: 106920
def selectionSort(A, N):
    cnt = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        cnt = cnt + int(i != minj)
        A[i], A[minj] = A[minj], A[i]
    return cnt

N = int(input())
A = [int(i) for i in input().split()]
cnt = selectionSort(A, N)

for i in range(N):
    if i != 0:
        print(" ", end = "")
    print(A[i], end = "")
    

print()
print(cnt)



Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C; 
    vector<ll> p(A);
    vector<ll> q(B);
    vector<ll> r(C);
    rep(i, A) { cin >> p[i]; }
    rep(i, B) { cin >> q[i]; }
    rep(i, C) { cin >> r[i]; }
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> pd(p.begin(), p.begin()+X);
    vector<ll> qd(q.begin(), q.begin()+Y);

    vector<ll> pqd;
    rep(i, pd.size()){
        pqd.push_back(pd[i]);
    }
    rep(i, qd.size()){
        pqd.push_back(qd[i]);
    }

    sort(pqd.begin(), pqd.end(), greater<ll>());
    vector<ll> sum;
    sum.push_back(0);

    ll tmp = 0;
    rep(i, pqd.size()){
        tmp += pqd[i];
        sum.push_back(tmp);
    }    
    //cout << pqd.size() << sum.size() <<endl;

    ll total_max = sum[pqd.size()];
    ll r_sum = 0;

    rep(i, r.size()){
        r_sum += r[i];
        if (i >= X + Y) break;
        ll total = r_sum + sum[X + Y - 1 - i];
        total_max = max(total_max, total);
    }

    cout << total_max << endl;
}

Measured memory_bytes: 8432
#include<stdio.h>

int main (void) {

  int A,B;
  char op;
  int ans;
  scanf("%d %c %d",&A,&op,&B);

  if(op == '+'){
    ans = A + B;
  } else {
    ans = A - B;
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string text;
    string pattern;
    cin >> text;
    cin >> pattern;
    
    //textをpattern見つけやすいようにいいじる
    text += text.substr(0, pattern.size() - 1);
    if(regex_search(text, regex(pattern))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3324
#include <stdio.h>
 
int main(void){
  int k, a, b, i=0;
  scanf("%d", &k);
  scanf("%d %d", &a, &b);
  for(i=a;i<=b;i++){
    if(i%k == 0){
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main(){
    int n;cin >> n;
    vector<int> x(n),y(n),h(n);
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int cx=0;cx<=100;cx++){
        for(int cy=0;cy<=100;cy++){
            int H=-1;
            int hmax = 2e9;
            bool success = true;
            for(int i=0;i<n;i++){
                int d = abs(cx-x[i])+abs(cy-y[i]);
                if(h[i]>0){
                    int h2 = h[i]+d;
                    if(H>0&&H!=h2){
                        success = false;
                        break;
                    }else{
                        H =h2;
                    }
                }else{
                        hmax = min(hmax,d);
                    }
            }
            if(success && H<=hmax){
                cout << cx << " " << cy << " " << H << endl;
            }
        }
    }
        
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = z()
A = zz()

np.argmax(A)
part_max = [0]*N
# 自分より前のMAXを求める
for i in range(1, N):
    part_max[i] = max(A[i-1], part_max[i-1])
ans = [0]*N
for i in range(N):
    ans[i] = max(part_max[i]-A[i], 0)
print(sum(ans))


Measured memory_bytes: 66576
def main():
    a = list(map(int, input().split()))
    a_set = list(set(a))
    c = 0
    for x in range(3):
        if a_set[0] == a[x]:
            c += 1
    if c == 2:
        print(a_set[1])
    else:
        print(a_set[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
    #include <chrono>
  
    using namespace std;
    using namespace std::chrono; 
 
    typedef long long int ll;
 
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }
    
    ll MAX = 1e18;
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      long double a,b;
      cin>>a>>b;
      long double t = a*b;
      ll ans = t;
      cout<<ans<<endl;
 
    }


Measured memory_bytes: 3756
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

S = [0] * N
for a in A:
    S[a-1] += 1

for i in range(N):
    if K - Q + S[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 56536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod=1000000007;
const int SIZE=510000;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

ll modpow(ll a, ll b, ll m){
    ll res=1, p=0, now=a%m;
    b %= (m-1);
    for(int i=0; b>p; ++i){
        if(b&((ll) 1<<i)){
            res=(res*now)%m;
            p |= ((ll) 1<<i);
        }
        now=(now*now)%m;
    }
    return res;
}
ll modinv(ll a, ll m){
    return modpow(a, m-2, m);
}
ll moddiv(ll a, ll b, ll m){
    return (a*modinv(b, m))%m;
}

ll f(ll n, ll a){
	ll s=1, t=1;
	for(ll i=0; i<a; ++i) (s *= n-i) %= mod;
	for(ll i=1; i<=a; ++i) (t *= i) %= mod;
	return moddiv(s, t, mod);
}

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans=(modpow(2, n, mod)-1)%mod;
	ans += mod;
	(ans -= (f(n, a)+f(n, b))%mod) %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool board[8][8];
char grid[8][8];
int upperlim = (1 << 8) - 1;

void solve(int row, int ld, int rd, int d)
{
    // cout<<d<<endl;
    if (d == 8)
    {
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (board[i][j] && grid[i][j]!='Q') return;  
            }  
        }

        for (int i = 0; i < 8; ++i)
         {
             for (int j = 0; j < 8; ++j)
             {
                 cout<<grid[i][j];
             }
             cout<<endl;
         } 
         return;
    }

    if (row != upperlim)
    { 
        int pos = upperlim & ~(row | ld | rd);
        while (pos)
        { 
            // cout<<"pos:"<<pos<<endl;
            int p = pos & (~pos + 1);
            // cout<<"p:"<<p<<endl;
            int num = p;
            int col = 0;
            while(num != 1) {
                num = num>>1;
                col++;
            }
            grid[d][col] = 'Q';
            pos = pos - p;
            solve(row + p, (ld + p) << 1, (rd + p) >> 1, d+1);
            grid[d][col] = '.';
        } 
    } 

    return;
}


int main()
{
    int k;
    cin>>k;
    for (int i = 0; i < 8; ++i)
    {
        for (int j = 0; j < 8; ++j)
        {
            board[i][j] = false;
            grid[i][j] = '.';
        }
    }
    for (int i = 0; i < k; i++)
    {
        int r,c;
        cin>>r>>c;
        board[r][c] = true;
    } 
    
    solve(0, 0 , 0, 0);

    return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int p[N];
    for(int i= 0;i<N;i++)
    {
        cin>>p[i];
    }

    int count = 0;
    for(int i= 0;i<N;i++)
    {
        if(p[i]!=i+1)
        {
            count++;
        }
    }
    if(count==0||count==2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    long int N, M, max, tmp, comp = 0;
    long int A[100] = {0};
    scanf("%ld %ld", &N, &M);

    for (long int i = 0; i < N; i++)
    {
        scanf("%ld", &A[i]);
    }

    for (long int k = 0; k < M; k++)
    {
        for (long int j = k+1; j < N; j++)
        {
            max = A[k];
            if (max < A[j])
            {
                tmp = A[k];
                A[k] = A[j];
                A[j] = tmp;
            }
        }
    
    }

    for (long int x = 0; x < N; x++)
    {
        comp += A[x];
    }
    

    if (A[M-1] > comp/(4*M) || A[M-1] == comp/(4*M) && comp%(4*M) == 0)
    {
        printf("Yes");
    }

    else
    {
        printf("No");
    }
    
    
    
    return 0;
}

Measured memory_bytes: 128
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long wa = sp[0];
        wa += sp[1];
        if (wa % 2 == 1)
        {
            Console.WriteLine("IMPOSSIBLE");
        }
        else
        {
            Console.WriteLine(wa / 2);
        }
    }


}


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

int main(){
	char s[100001] = {};
	long dp[100001][4] = {};
	int mod = 1000000007;

	scanf("%s", s);
	int n = strlen(s);
	for(int i=n; i >= 0; i--) {
		for(int j=3; j >= 0; j--) {
			if(i == n) {
				dp[i][j] = (j == 3) ? 1 : 0;
			}else{
				int m = (s[i] == '?') ? 3 : 1;
				char str[4] = "ABC";
				dp[i][j] = m * dp[i+1][j];
				if(j < 3 && (m == 3 || s[i] == str[j]))
					dp[i][j] += dp[i+1][j+1];
				dp[i][j] %= mod;
			}
		}
	}
	printf("%ld\n", dp[0][0]);
}

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

LL N,K;
const LL MOD = 1000000007ll;

LL m_pow(LL a,LL x)
{
    if(x == 0)return 1;
    LL half = m_pow(a,x/2);
    half *= half;
    half %= MOD;
    return (half * (x % 2 ? a : 1))%MOD;
}

map<LL,LL>memo;
LL dp(LL d)
{
    if(memo.count(d))return memo[d];
    LL res = m_pow(K,(d+1)/2);
    vector<int>div;
    for(int i = 1;i * i <= d;++i)
    {
        if(d % i == 0)
        {
            div.push_back(i);
            if(d/i != i)div.push_back(d/i);
        }
    }
    for(int dash : div)
    {
        if(dash == d)continue;
        res -= dp(dash);
        res += MOD;
        res %= MOD;
    }
    return memo[d] = res;
}

int main()
{
    cin >> N >> K;
    dp(N);
    LL ans = 0;
    for(auto p : memo)
    {
        LL index = p.first;
        LL value = p.second;
        if(index % 2 == 0)
        {
            value *= index / 2;
        }
        else
        {
            value *= index;
        }
        /*
        cerr << index << endl;
        cerr << value << endl;
        //*/
        value %= MOD;
        ans += value;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr



A, B = map(int, input().split())

fac_A = factorization(A)
fac_B = factorization(B)

prime_A = [f[0] for f in fac_A]
prime_B = [f[0] for f in fac_B]

if 1 in prime_A: prime_A.remove(1)
if 1 in prime_B: prime_B.remove(1)
common = set(prime_A) & set(prime_B)
print(len(common)+1)


Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) {
		
		int x;

		InputStreamReader isr=new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		String str=null;
		
		try{
			str=br.readLine();
			br.close();
		}catch(IOException e) {
			e.printStackTrace();
		}
		x=Integer.parseInt(str);
		System.out.println(x*x*x);
	}

}



Measured memory_bytes: 24132
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n";
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=5e5+10;
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=0;i<=1000;i++)
    {
        for(int j=-1000;j<=1000;j++)
        {
            int k=i*i*i*i*i*1LL-j*j*j*j*j*1LL;
            if(k==n)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    
    
}

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

int main(){
	int n,m;cin>>n>>m;
	vector<int> low(m);
	vector<int> high(m);
	for(int i=0;i<m;i++){
		cin>>low.at(i)>>high.at(i);
	}
	sort(low.begin(),low.end());
	sort(high.begin(),high.end());
	if((high.at(0)-low.at(m-1)+1)>0){
      cout<<high.at(0)-low.at(m-1)+1<<endl;
    }else{
      cout<<0<<endl;
    }
  return 0;
}

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

using namespace std;

using ll = long long;

string Solve() {
    string in;
    cin >> in;

    int a[4];
    for (int i = 0; i < 4; ++i)
        a[i] = (int)(in[i] - '0');

    int op[2] = {1, -1};
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < 2; ++j)
            for (int k = 0; k < 2; ++k) {
                if (a[0] + op[i] * a[1] + op[j] * a[2] + op[k] * a[3] == 7) {
                    string s = to_string(a[0]) + (i == 0 ? '+' : '-')
                        + to_string(a[1]) + (j == 0 ? '+' : '-')
                        + to_string(a[2]) + (k == 0 ? '+' : '-')
                        + to_string(a[3]) + "=7";
                    return s;
                }
            }
    return "";
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S = []
for i in range(N):
    S.append(str(input()))

d = defaultdict(int)
for i in range(N):
    d[S[i]] += 1

k = 0
ans = []
for x in d.items():
    if x[1] > k:
        k = x[1]
        ans = [x[0]]
    elif x[1] == k:
        ans.append(x[0])
    else:
        pass

ans.sort()
for a in ans:
    print(a)


Measured memory_bytes: 90324
import scala.io.{StdIn => in}

object Main extends App {
  val Array(a, b) = in.readLine.split(" ").map(_.toLong)

  def calc(n:Long):Long = {
    val num = n + 1  // 0から数えるので -> 0が１個目
    var ret = 0L
    // i桁目の1の偶奇を調べる
    for(i <- 0 until 40) {
      // 0桁目 -> cycle 2 (0 1 0 1 0 1 0 1)
      // 1桁目 -> cycle 4 (0 0 1 1 0 0 1 1)
      val cycle = 1L << (i+1)
      // cycleCnt は num を cycle した回数 × cycle/2回 1が出現する
      // ＋ cycle整数回の余り
      var cycleCnt = (num / cycle) * (cycle / 2)
      // 0 0 1 1 の cycle=4 の時 余が 0 0 1の場合(余3) 2(<-4/2※cycle/2)を引くと 1 の個数が分かる
      // 余が 0 の場合(余1) に 2を引くと -1 になるため、その時は 0 にする
      var rem =  math.max(0L, (num % cycle) - (cycle / 2))

      debug(i+1, num, cycle, cycleCnt, "=", num/cycle, "*", cycle/2, "+", rem)

      cycleCnt += rem

      // i桁目が奇数(1になる)時は加算する
      if(cycleCnt % 2 == 1) ret += 1L << i
    }

    ret
  }

  // 0からbまでのXORした結果から0からa-1までの結果を引くとaからbまでの結果になる
  // ex) 4~12 までの足し算は 0~12 - 0~3 と同じ(XORでも同じ)
  val ans = calc(b) ^ calc(a-1)
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString == "class Main$") return
    println(any.mkString(" "))
  }
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0;i < n;++i) {
        cout << (s[i] == '?' ? char('D') : s[i]);
    }
    cout << endl;
}

Measured memory_bytes: 3752
#!/usr/bin/python

import sys

def main(argv):
    N = sys.stdin.readline()
    while N:
        A = [int(raw_input()) - 1 for i in xrange(0, int(N))]

        counter = 0
        visited = set()
        index = 0
        while index != 1 and index not in visited:
            visited.add(index)
            counter += 1
            index = A[index]

        if index != 1:
            counter = -1
        print("{0}".format(counter))

        N = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 12116
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map(String::toInt)

    var result = mutableListOf<Int>()

    for (i in list[0]..list[1]) {

        // ロジックが汚い。やりたいことは剰余と商を求めること
        // 商と余りのPair型で返却するfunctionを作成してみる？
        val five = i / 10
        val fivex = i % 10
        val four = five / 10
        val fourx = five % 10
        val three = four / 10
        val two = three / 10
        val twox = three % 10
        val one = two / 10
        val onex = two % 10

        if (onex == fivex && twox == fourx)
            result.add(i)
    }
    println(result.size)
}

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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var H = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var temp = 0;
        var result = 0;

        for (int i = 0; i < N - 1; i++)
        {
            if (H[i + 1] <= H[i])
            {
                temp++;
                if (temp > result)
                {
                    result = temp;
                }
            }
            else
            {
                temp = 0;
            }
        }
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 28124
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n, m, i, j, flag, t, k;
	int a[111], b[111];
	while(~scanf("%d %d", &n, &m)){
		for(i = 0, j = 0; i < n; i++){
			scanf("%d %d", &t, &k);
			if(k <= m) a[j++] = t;
		}
		sort(a, a + j);
		if(j) cout << a[0] << endl;
		else cout << "TLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, y; cin >> n >> y;
    
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    
    return 0;
}


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

int main() {
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x + r<=W&&x - r>=0&&y + r<=H&&y - r>=0){
    	cout<<"Yes"<<endl;
    }else if(x + r>W||x - r<0||y + r>H||y - r<0){ 
        cout<<"No"<<endl;
}
}    



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

#define   Pi     2*acos(0.0)
#define   LINF   1LL<<63
#define   ll     long long
#define   ull    unsigned long long
#define   pb     push_back
#define   mp     make_pair
#define   MAX    500006
#define   MAX1   10000008
#define   mem(a,v)   memset(a,v,sizeof(a))
#define   all(x) x.begin(),x.end()
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define yes   cout<<"YES"<<endl
#define no   cout<<"NO"<<endl
#define buga  cout<<1<<endl
#define bugb  cout<<2<<endl
#define bugc  cout<<3<<endl
#define bugd  cout<<4<<endl
#define buge  cout<<5<<endl

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll parent[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

/*
ll bin_pow(ll o, ll s) {
    if (s == 0) return 1;
    if (s == 1) return o % mod;
    ll d = bin_pow(o, s/2);
    d = (d * 1ll * d) % mod;
    if (s % 2 == 1)
        d = (d * 1ll * o) % mod;
    return d;
}
*/
ll Max=1;

int findparent(int r){
    if (parent[r]==r)return r;
    else return parent[r]=findparent(parent[r]);
}

void Union(int a,int b){
    int u=a;
    int v=b;
    int parenta=findparent(u);
    int parentb=findparent(v);
    if(parenta!=parentb){
        parent[parentb]=parenta;
        B[parenta]+=B[parentb];
        B[parentb]=0;
        Max=max(B[parenta],Max);
    }
}

int main ()
{
    fastIO();
    ll a,b,c,d,n,m,k,l,p,q,r,t,x,y;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    ll Max1=-1e18+1,Min=LINF;
    string s,s1,s3,s4;

    //cin>>n;
    //cin>>t;
    t=1;

    while(t--){
        cin>>n>>m;
        for(int i=1;i<=n;i++){parent[i]=i;B[i]=1;}

        for(int i=0;i<m;i++){
            cin>>a>>b;
            VP.pb(mp(a,b));
        }
        //sort(VP.begin(),VP.end());
        for(int i=0;i<VP.size();i++){
            //if(VP[i].first==VP[i+1].first&&VP[i].second==VP[i+1].second&&i!=m-1)continue;
            Union(VP[i].first,VP[i].second);
           // cout<<Max<<endl;
        }
        cout<<Max<<endl;

    }

    return 0;
}


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

int main()
{
int n;
cin>>n;
int t1=0,x1=0;int f=1,i,j,q=0,x[n],y[n],t[n];
for(i=0;i<n;i++)
{
	cin>>t[i]>>x[i]>>y[i];
	if(x[i]+y[i]<=t[i]&&(x[i]+y[i]-t[i])%2==0)
q++;
}
if(q==n)cout<<"Yes";
else cout<<"No";
return 0;
}

Measured memory_bytes: 1408
<?php
define("MOD", 10**9+7);
$N = int();
for($i = 0; $i < $N; $i++){
  $A[] = int();
}
$last = array_fill(1, $N, false);
$dp = array_fill(0, $N+1, 0);
$dp[0] = 1;
for($i = 1; $i <= $N; $i++){
  $a = $A[$i-1];
  $dp[$i] = $dp[$i-1];
  if($last[$a] !== false && $last[$a] < $i - 1){
    $dp[$i] += $dp[$last[$a]];
  }
  $dp[$i]%=MOD;
  $last[$a] = $i;
}
echo $dp[$N];

function int(){
  return intval(trim(fgets(STDIN)));
}


Measured memory_bytes: 37364
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = map(int, input().split())
abcd = [0] * q
for i in range(q):
    abcd[i] = list(map(int, input().split()))

def dfs(seq):
    if len(seq) == n:
        yield tuple(seq)
        return
    if len(seq) == 0:
        start = 1
    else:
        start = seq[-1]
    for i in range(start, m+1):
        new_seq = seq.copy()
        new_seq.append(i)
        yield from dfs(new_seq)

ans = 0
for s in dfs([]):
    tmp_ans = 0
    for a, b, c, d in abcd:
        if s[b-1] - s[a-1] == c:
            tmp_ans += d
    ans = max(ans, tmp_ans)
print(ans)


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

int main()
{   
    bool chk=true;
    int count=0;
    int N;
    cin >> N;
    if(N==2)
    {
        cout << 2 <<endl;
        return 0;
    }

    for(int i=N; i<=1000000; i++)
    {
        for(int j=2; j<i; ++j)
        {
            if (i%j==0)
            {
                chk=false;
                break;
            }
        }
        if(chk)
        {
            break;
        }
        else
        {
            count++;
            chk=true;
        }  
    }
       cout << N+count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll N;
  cin>>N;

  vector<ll> mn;
  vector<ll> mx;
  mn.emplace_back(0);
  mx.emplace_back(0);
  ll curMn=0,curMx=0;
  rep(i,0,50) {
    if (i%2==0) curMx+=1ll<<i; else curMn-=1ll<<i;
    mn.emplace_back(curMn);
    mx.emplace_back(curMx);
  }

  string res;
  per(i,0,50) {
    if (N<mn[i] || N>mx[i]) {
      if (i%2==0) N-=1ll<<i; else N+=1ll<<i;
      res+='1';
    } else {
      if (!res.empty()) res+='0';
    }
  }
  if (res.empty()) res+='0';
  cout<<res<<"\n";
}


Measured memory_bytes: 256
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define forn(i,a,b) for (int i = a; i <= b; i ++ )
#define mod(n,k) (((n%k)+k)%k)
using namespace std;
typedef long long ll;

int main()
{
    optimiza_io
    long double R;
    cin >> R;
    cout << fixed << setprecision( 2 ) << R * 2 * 3.14 << "\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3800
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }.toIntArray()
private fun readLongs() = readStrings().map { it.toLong() }.toLongArray()

fun main(args: Array<String>) {
  var n = readInt()
  var a = 0
  var b = 0
  var c = 0
  while (n > 0) {
    var (t, x, y) = readInts()
    var d = Math.abs(x - a) + Math.abs(y - b)
    if (t - c >= d && (t - c) % 2 == d % 2) {
      a = x
      b = y
      c = t
    }
    else {
      println("No")
      System.exit(0)
    }
    n -= 1
  }
  println("Yes")
}


Measured memory_bytes: 50336
/*
f[i][j] 表示要让i活着必须要杀掉j 

*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
# define LL long long
const int M = 405 ;
const int N = 100005 ;
using namespace std ;
inline int read() {
	char c = getchar() ; int x = 0 , w = 1 ;
	while(c>'9'||c<'0') { if(c=='-') w = -1 ; c = getchar() ; }
	while(c>='0'&&c<='9') { x = x*10+c-'0' ; c = getchar() ; }
	return x*w ;
}
LL Ans ;
int n , m ;
int a[N] , b[N] ;
bool f[M][M] , die[M] ;
int main() {
	n = read() , m = read() ;
	for(int i = 1 ; i <= m ; i ++) 
	    a[i] = read() , b[i] = read() ;
	for(int i = 1 ; i <= n ; i ++) {
		f[i][i] = true ;
	    for(int j = m ; j >= 1 ; j --) {
	    	bool x = f[i][a[j]] , y = f[i][b[j]] ;
//  x : 目前a[j]是否死了 
//  y : 目前b[j]是否死了
            if(x & y) { die[i] = true ;  break ; }
		    else if(x) f[i][b[j]] = true ;
		    else if(y) f[i][a[j]] = true ;
		}
	}
	for(int i = 1 , tot ; i < n ; i ++) {
		if(die[i]) continue ;
		for(int j = i + 1 ; j <= n ; j ++) {
			if(die[j]) continue ;
			tot = 1 ;
			for(int k = 1 ; k <= n ; k ++)
			    if(f[i][k] & f[j][k])
			        tot = 0 ;
			Ans += tot ;
		}
	}
	cout << Ans << endl ;
	return 0 ;
}

Measured memory_bytes: 1152
/* Be strong, be fearless, be beautiful :D
And believe that anything is possible :))
when you have the right people there
to support you :) */
//RTn_E
#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;
#define _Sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define _file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld long double
#define sp setprecision
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define pii pair < int , int >
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 100;
const ll inf = 1e18;

//Main CODE :/\

int a[maxn];
int main() {
    _Sync
    int n , k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int pos = 0 , posin = 0;
    for (int i = 0; i < n; i++)
        if (a[i] > 0){
            posin = i;
            break;
        }
    int ans = 1e9;
    for (int i = k - 1; i < n; i++){
        int r = abs(a[i] - a[i - k + 1]) + abs(a[i - k + 1]);
        int l = r + abs(a[i]) - abs(a[i - k + 1]);
        ans = min({ans , l , r});
    }
    cout << ans << "\n";
    return 0;
}
//The_End
//Game Over :D


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
    int X;
    scanf("%d",&X);
    if(X==3||X==5||X==7){
        printf("%s\n","YES");
    }else{
        printf("%s\n","NO");
        }
        return 0;
}

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

const int mxN = 2e5 + 5;
int a[mxN];

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	bool zero = false;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		cnt += a[i] < 0;
		zero |= a[i] == 0;
		a[i] = max(a[i], -a[i]);
	}
	if(zero) {
		long long tot = 0;
		for(int i = 0; i < n; ++i)
			tot += a[i];
		return cout << tot, 0;
	}
	sort(a, a + n);
	cnt %= 2;
	long long tot = cnt % 2 ? -a[0] : a[0];
	for(int i = 1; i < n; ++i)
		tot += a[i];
	cout << tot;
}


Measured memory_bytes: 4020
#include<stdio.h>

int A[11]={0,1,2,3,4,5,6,7,8,9,0};
int cnt=0;
int C[10];

void dfs(int i,int rest,int d,int n){
int j;

 if(i<11){
  if(d==n){
 /*   for(j=0;j<n;j++)printf("%d ",C[j]);
    printf("\n");*/
    if(rest==0){cnt++;return;}
    else return;
  }
  if(rest<0)return;

    C[d]=A[i];
    dfs(i+1,rest-A[i],d+1,n);
 
    dfs(i+1,rest,d,n);

 }

return;
}




int main(){
 int n,s;
 int ans;

 while(1){

      scanf("%d %d",&n,&s);
      if(n==0 && s==0)break;
      if(s > 55)printf("0\n");
      else {
            cnt=0;
            dfs(0,s,0,n);
            printf("%d\n",cnt);

      }

 }

 return 0;
}


Measured memory_bytes: 2032
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int div_500 = x / 500;
    int rem = x % 500;

    int div_5 = rem / 5;

    cout << (div_500 * 1000) + (div_5 * 5) << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
    int N,X,Y;

    cin >> N >> X >> Y;

    int ans[N];
    
    for(int i=0;i<N;i++){
        ans[i] = 0;
    }
        
        for(int i=1;i<=N-1;i++){

            for(int j=i+1;j<=N;j++){
                int a = min(j-i, min(abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)));
                ans[a] ++;
            }
        }

        for(int i=1;i<N;i++){
            cout << ans[i] << endl;

        }
    
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::{input, marker::Chars};

fn main() {
    input!(h: usize, _w: usize, _k: usize, s: [Chars; h]);
    let ans = s.iter().scan(0, |cnt, row| {
        if let Some(p) = row.iter().position(|&c| c == '#') {
            let res = row
                .iter()
                .enumerate()
                .map(|(i, &c)| {
                    *cnt += (c == '#') as usize;
                    (*cnt + (i < p) as usize).to_string()
                })
                .collect_vec()
                .join(" ");
            Some(Some(res))
        } else {
            Some(None)
        }
    });
    let first_some = ans.clone().find(|it| it.is_some()).unwrap();
    let ans = ans
        .scan(first_some, |pre, it| {
            *pre = it.or(pre.clone());
            Some(pre.clone().unwrap())
        })
        .collect_vec()
        .join("\n");
    println!("{}", ans);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  int max = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++){
    if (max < A[i]){
      max = A[i];
    }
    sum += max-A[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3944
#include <algorithm>
#include <cstdio>
#include <map>

using namespace std ;

typedef long long LL ;
const int N=100 ;
typedef pair<LL,LL> pii ;

LL x[N] , y[N] ;
map<pii,int>id;
int f[N] , v[N] ;
int n ;
inline int find ( int x ) { return f[x]==x?x:f[x]=find(f[x]); }
inline int solve ( int a , int b )
{
    LL p=x[a]-x[b] , q=y[a]-y[b] ;
    int i , t ;
    if ( !p && !q ) return N ;
    id.clear();
    for ( i=1 ; i<=n ; i++ ) f[i]=i,id[make_pair(x[i],y[i])]=i,v[i]=0;
    for ( i=1 ; i<=n ; i++ ) 
    {
        t=id[make_pair(x[i]-p,y[i]-q)] ;
        if ( t ) f[find(t)]=find(i);
    }
    int res=0 ;
    for ( i=1 ; i<=n ; i++ ) 
        if ( !v[find(i)] ) v[find(i)]=1,res++;
    return res ;
}

int main ()
{
    int i , j ;
    scanf("%d",&n);
    for ( i=1 ; i<=n ; i++ ) scanf("%lld%lld",x+i,y+i);
    int res=N ;
    for ( i=1 ; i<=n ; i++ ) 
        for ( j=1 ; j<=n ; j++ ) 
            if ( i^j ) res=min(res,solve(i,j));
    printf("%d\n",res<N?res:1);
    return 0 ;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    long double V[3010];
    rep(i,n)cin>>V[i];
    vector<vector<long double>>dp(3010,vector<long double>(3010,0));
    dp[0][0]=1.0;
    rep(i,n)rep(j,n){
        dp[i+1][j]+=dp[i][j]*(1-V[i]);
        dp[i+1][j+1]+=dp[i][j]*V[i];
    }
    long double ans=0.0;
    //rep(i,n+1){rep(j,n+1)cout<<dp[i][j]<<' ';
      //  cout<<endl;
    //}
    rep(i,n/2+1){
        ans+=dp[n][n-i];
    }
    cout<<fixed<<setprecision(12);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 142080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
long long MOD = 1e9+7;
long long INF = 1e15;
typedef pair<long long, long long> P;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    string S;
    vector<int> edge[N+1];
    rep2(i, 1, N+1){
        cin >> S;
        rep(j, N){
            if(S[j] == '1'){
                edge[i].push_back(j+1);
            }
        }
    }
    int ans[N+1];
    rep2(i, 1, N+1){
        bool able = true;
        bool fins = false;
        set<int> used;
        set<int> used2[N+2];
        vector<int> group[N+2];
        int count = 0;
        group[1].push_back(i);
        count++;
        used.insert(i);
        used2[1].insert(i);
        if(group[1].size() == N){
            fins = true;
        }
        while(able && !fins){
            int n = group[count].size();
            rep(i, n){
                int j = group[count][i];
                rep(k, edge[j].size()){
                    int l = edge[j][k];
                    if(!used.count(l)){
                        used.insert(l);
                        used2[count+1].insert(l);
                        group[count+1].push_back(l);
                    }
                    else if(count >= 2 && !used2[count+1].count(l) && !used2[count-1].count(l)){
                        able = false;
                        break;  
                    }
                }
            }
            if(group[count+1].size() == 0) fins = true;
            else count++;
        }
        if(able) ans[i] = count;
        else ans[i] = -1;
    }
    int answer = -1;
    rep2(i, 1, N+1){
        answer = max(answer, ans[i]);
    }
    cout << answer << endl;
}

Measured memory_bytes: 512