akhauriyash/Code-Regression huggingface dataset:
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
B=[int(input()) for _ in range(N)]
S=[[0,0,0] for _ in range(3)]
for b in B:
  for i in range(3):
    if b in A[i]:
      S[i][A[i].index(b)] = 1
      break
p = False
for a in S:
  if sum(a)==3:
    p = True
    break
if not p:
  for i in range(3):
    if S[0][i]+S[1][i]+S[2][i]==3:
      p = True
      break
if not p:
  if S[0][0]+S[1][1]+S[2][2]==3 or S[2][0]+S[1][1]+S[0][2]==3:
    p=True
print("Yes" if p else "No")

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,a[100005],p[100005],nfac=1;
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void solve(){
    int ans=0;
    cin>>n;
    rep(i,1,n+1){
        p[i]=(expo(i,hell-2,hell)+p[i-1])%hell;
        nfac=nfac*i%hell;
    }
    rep(i,1,n+1){
        cin>>a[i];
        int temp=a[i]*(p[n-i+1]+p[i]+hell-1)%hell;
        ans=(ans+temp)%hell;   
    }
    cout<<ans*nfac%hell;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
//package cp;
import java.util.*;
import java.io.*;
public class Main {
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	void swap(long a,long b) {long temp=a;a=b;b=temp;}
	StringBuilder sb=new StringBuilder();
	Integer[] ARR=new Integer[5];
	//Integer sort-TLE-Initialize object elements i.e a[0].
	long ceil(int n) {return (long)Math.ceil(1.0*n/2);}
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		int n=Readers.nextInt();
		System.out.println((n-2)*180);
		out.flush();
	}

}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


Measured memory_bytes: 32676
H,W,A,B=map(int,input().split())
N=H+W+2
mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
ans=0
for i in range(H-A):
    t=table[B-1+i]*rtable[i]*rtable[B-1]
    s=table[W+H-B-i-2]*rtable[H-i-1]*rtable[W-B-1]
    t=(t*s)%mod
    #print(t)
    ans+=t
    ans%=mod
print(ans)

Measured memory_bytes: 44268
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100005

int parent[MAX];
vector<int> g[MAX], path;

void dfs(int u, int s) {
    int cnt = 0, tmp;
    parent[u] = s;
    path.push_back(u);
    for (int v = 0; v < g[u].size(); v++) {
        if (parent[g[u][v]] == 0) {
            dfs(g[u][v], u);
            if (s != u) {
                break;
            } else {
                cnt++;
                if (cnt == 1) {
                    for (int i = 0; i < path.size()/2; i++) {
                        tmp = path[i];
                        path[i] = path[path.size()-i-1];
                        path[path.size()-i-1] = tmp;
                    }
                } else {
                    break;
                }
            }
        }
    }
}

int main() {
    int n, m, u, v; cin >> n >> m;
    for (u = 1; u <= n; u++) parent[u] = 0;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (u = 1; u <= n; u++) {
        if (g[u].size() > 0) {
            dfs(u, u);
            break;
        }
    }
    cout << path.size() << '\n';
    for (int i = 0; i < path.size(); i++) {
        if (i > 0) cout << ' ';
        cout << path[i];
    }
    cout << '\n';
}


Measured memory_bytes: 11512
#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; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        if(500 * i + 100 * j + 50 * k == x) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
W,H,N = map(int,input().split())
W1 = []
W2 = []
H1 = []
H2 = []
W1.append(0)
W2.append(W)
H1.append(0)
H2.append(H)
for i in range(N) :
    x,y,a = map(int,input().split())
    if a == 1 :
        W1.append(x)
    if a == 2 :
        W2.append(x)
    if a == 3 :
        H1.append(y)
    if a == 4 :
        H2.append(y)
width = max(0,min(W2)-max(W1))
height = max(0,min(H2)-max(H1))
print(width*height)


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	while (cin >> a) {
		cin >> b >> c;
		a %= b;
		int answer = 0;
		for (int i = 0; i < c; ++i) {
			a *= 10;
			answer += a / b;
			a %= b;
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n, v, ans;
    const int MAX = 1e+5 + 1;
    scanf("%d", &n);
    // ary[0]: odd seq, ary[1]: even seq
    int ary[2][MAX] = {};
    rep(i, n){
        scanf("%d", &v);
        ary[i % 2][v]++;
    }
    // [0: most common num, 1: second most] [0: num, 1: cnt]
    int oo[2][2] = {}, ee[2][2] = {};
    rep(i, 2){
        rep(j, MAX){
            if(oo[i][1] < ary[0][j]){
                oo[i][0] = j;
                oo[i][1] = ary[0][j];
            }
            if(ee[i][1] < ary[1][j]){
                ee[i][0] = j;
                ee[i][1] = ary[1][j];
            }
        }
        ary[0][oo[i][0]] = 0;
        ary[1][ee[i][0]] = 0;
    }
    if(oo[0][0] != ee[0][0]){
        ans = n - oo[0][1] - ee[0][1]; 
    } else {
        ans = n - max(oo[1][1] + ee[0][1], oo[0][1] + ee[1][1]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;
typedef vector<ll>		VLL;
typedef vector<VLL>		VVLL;
typedef vector<VVLL>	VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
bool check(const VLL &movList, int movMax, int stPos, int endPos)
{
	if (movMax < abs(endPos)) {
		return false;
	}

	movMax++;
	int dpSizeMax = movMax * 2;
	VVLL dp(2, VLL(dpSizeMax, INF));
	stPos += movMax;
	endPos += movMax;

	int nowIdx = 0;
	int nextIdx = 1;
	dp[nowIdx][stPos] = 0;
	for (auto movOne : movList) {
		fill(&dp[nextIdx][0], &dp[nextIdx][dpSizeMax - 1], INF);
		REP(i, dpSizeMax) {
			if (0 == dp[nowIdx][i]) {
				dp[nextIdx][i + movOne] = 0;
				dp[nextIdx][i - movOne] = 0;
			}		
		}
		swap(nowIdx, nextIdx);
	}
	
	return dp[nowIdx][endPos] != INF;
}

int main()
{
	string s;
	int x, y;
	cin >> s >> x >> y;
	
	int stPos = 0;
	REP(i, s.size()) {
		if (s[i] == 'T') {
			break;
		}
		stPos++;
	}

	VLL xMov;
	VLL yMov;
	bool bXMove = true;
	int movDist = 0;
	int xMax = stPos;
	int yMax = 0;
	REPN(i, stPos, s.size()) {
		if (s[i] == 'T') {
			if (0 < movDist) {
				if (bXMove) {
					xMov.emplace_back(movDist);
					xMax += movDist;
				} else {
					yMov.emplace_back(movDist);
					yMax += movDist;
				}
			}
			movDist = 0;
			bXMove = !bXMove;
		} else {
			movDist++;
		}
	}

	if (0 < movDist) {
		if (bXMove) {
			xMov.emplace_back(movDist);
			xMax += movDist;
		} else {
			yMov.emplace_back(movDist);
			yMax += movDist;
		}
	}

	string ans = (check(xMov, xMax, stPos, x) && check(yMov, yMax, 0, y)) ? "Yes" : "No";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  int black = 0;
  vector<vector<char>> c(H+1, vector<char>(W+1));
  vector<int> rowb(H+1), colb(W+1);
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin >> c.at(i).at(j);
      if(c.at(i).at(j)=='#'){
        black++;
        rowb.at(i)++;
        colb.at(j)++;
      }
    }
  }
  int ans = 0;
  for(int tmp=0; tmp<(1<<12); tmp++){
    bitset<12> s(tmp);
    int eraceb = 0;
    for(int i=0; i<H; i++){
      if(s.test(i)){
        eraceb += rowb.at(i+1);
      }
    }
    for(int j=6; j<6+W; j++){
      if(s.test(j)){
        eraceb += colb.at(j-5);
      }
    }
    for(int i=0; i<H; i++){
      for(int j=6; j<6+W; j++){
        if(!s.test(i)||!s.test(j)) continue;
        if(c.at(i+1).at(j-5)=='#') eraceb--;
      }
    }
    if(black-eraceb==K) ans++;
  }
  int m = 1;
  for(int i=0; i<12-H-W; i++){
    m *= 2;
  }
  cout << ans/m;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define SQR(a) ((a)*(a))
using namespace std;
typedef long long int ll;
typedef pair<int,int> pr;
typedef pair<pr,ll> ppr;
typedef vector<pr> vpr;
const int INF=1<<30;
int n;
int count(int ball[10001]){
	int count=0,s=0,e=-1;
	FOR(i,1,n+1){
		if(ball[i]==ball[i-1])
		continue;
		if(i-count>=4){
			e=i-1;
			s=count;
			break;
		}
		count=i;
	}
	while(s && ball[e+1]==ball[s-1]){
		int ne=e+1,ns=s-1;
		while(ball[ne+1]==ball[e+1]) ne++;
		while(ns && ball[ns-1]==ball[s-1]) ns--;
		if(ne-e+s-ns>=4){
			e=ne;
			s=ns;
		}
		else 
		break;
	}
	return e-s+1;
}
int main() {
	
	while(cin >> n && n){
	int ball[10001]={},maxim =0;
	REP(i,n)
		cin >> ball[i];
	ball[n]=-1;
	FOR(i,1,4)
		REP(j,n)
			if(ball[j]!=i){
				int base=ball[j];
				ball[j]=i;
				maxim =max(maxim,count(ball));
				ball[j]=base;
			}
	cout << n-maxim << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a;
	string s;
	cin>>a>>s;
	if(a >= 3200)cout<<s<<endl;
	else cout<<"red"<<endl;
	return 0;
}


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

using namespace std;

int main(){
    int H, W;
    while(1){
    cin >> H >> W;
    if( H == 0 && W == 0){
        break;
    }
    else{
    for (int i = 0; i < H; i++){
        if (i == 0 || i == H - 1){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
            cout << endl;
        }
        else{
            cout << "#";
            for(int j = 0; j < W - 2; j++){
                cout << ".";
            }
            cout << "#" << endl;
        }
    }
    printf("\n");
    }
    }
    return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
int n,x[100100],L,f[100100][25],Q,l,r;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	scanf("%d",&L);
	int pre=n;
	for(int i=n,pre=n;i>=1;i--){
		while(x[i]+L<x[pre])pre--;
		f[i][0]=pre;
	}
	for(int i=1;i<=20;i++)
		for(int j=1;j<=n;j++){
			if(f[j][i-1]==n)f[j][i]=n;
			else f[j][i]=f[f[j][i-1]][i-1];
		}
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d",&l,&r);
		if(l>r)l^=r^=l^=r;
		int ans=0;
		for(int i=20;i>=0;)
			if(f[l][i]<r)ans+=1<<i,l=f[l][i];
			else i--;
		printf("%d\n",ans+1);
	}
} 

Measured memory_bytes: 10880
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll n,a,b;
    cin >> n >> a >> b;
    ll c=a+b;
    ll ans=ll(n/c)*a;
    ll r=n%c;
    ans+=(a<r)?a:r;
    cout << ans << endl;


    return 0;   
}

Measured memory_bytes: 3632
// Problem : D - Lunlun Number
// Contest : AtCoder - AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int k;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>k;
    queue<int> q;
    for(int i=1;i<=9;i++) q.push(i);
    int x;
    while(k--){
        x = q.front();
        q.pop();
        if(x % 10 != 0) q.push(10*x + x%10 - 1);
        q.push(10*x + x%10);
        if(x % 10 != 9) q.push(10*x + x%10 + 1);
    }
    cout<<x<<endl;
    return 0;
}


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

int main(void) {
	int i,j,k,cn[105][4],m[32],d[33],t,n,x,y;
	double s,g;
	char a[]="0123456889abcdef",b[9];
	for (i=0,t=48; i<16; i++) {	if (i==10) t=87;
	for (j=0;j<4;j++) if ((i & (1 << j))>0) cn[i+t][j]=1; else cn[i+t][j]=0;}
    for (i=7,x=1;i<32;i++,x*=2) d[i]=x;
	for (i=6,s=0.5;i>-1;i--,s/=2) d[i]=(int)(s*10000000); 
	cin >> n;
	for (k=0;k<n;k++) {
		cin >> b; t=31;
		for (j=0;j<8;j++) for(i=0;i<4;i++) m[t--]=cn[(int)b[j]][3-i]; 
		if (m[31]==1) cout << "-";
		for (i=7,x=0;i<31;i++) if (m[i]==1) x+=d[i];
		for (i=0,y=0;i<7;i++) if (m[i]==1) y+=d[i];
		if (y==0) cout << x  << ".0" << endl; else {
		 cout << x << "."; 
		 for (i=1000000;i>0;i/=10) if (i>y) cout << "0";
		 while( y>10 && (y % 10)==0) y=y/10;
		 cout << y << endl;
		}
		}
	return 0;
	}



Measured memory_bytes: 3108
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const R = Number(input[0][0]);
  const G = Number(input[1][0]);

  return G * 2 - R;
};

console.log(main(read()));


Measured memory_bytes: 29808
#include <iostream>
using namespace std;
int cnt, m;
int G[101];

void insertionSort(int A[], int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i-g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  cnt = 0;
  int h = 1;
  for (m = 0; h <= n; m++) {
    G[m] = h;
    h = 4*h + 1;
  }
  for (int i = m-1; i >= 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

int main() {
  int n; cin >> n;
  int A[1000001];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  shellSort(A, n);
  cout << m << endl;
  for (int i = m-1; i >= 0; i--) {
    cout << G[i];
    if (i != 0) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << A[i] << endl; 
  } 
    
}




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

using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);

double a, b, x;
bool ok(double ang) {
	if (a - b * tan(ang) > eps) {
		double ap = b * tan(ang);
		double area = 0.5 * ap * b;
		area *= a;
		if (abs(area - x) < eps || x - area > eps) return true;
		return false;
	} else {
		double bp = a / tan(ang);
		double a1 = 0.5 * a * bp;
		double a2 = a * (b - bp);
		double area = a1 + a2;
		area *= a;
		if (abs(area - x) < eps || x - area > eps) return true;
		return false;
	}
}

int main() {
	cin >> a >> b >> x;
	double lo = 0, hi = pi / 2;
	double ans = 0;
	while (hi - lo > eps) {
		double mid = (lo + hi) / 2;
		if (ok(mid)) {
			ans = mid;
			lo = mid;
		} else {
			hi = mid;
		}
	}

	ans = pi / 2 - ans;
	cout << fixed << setprecision(10) << (ans * 180) / pi << endl;
}

Measured memory_bytes: 256
def solve():
    line = input()
    while True:
        surface = list(map(int, line))
        for _ in range(7):
            surface.extend(map(int, input()))
        
        for i, v in enumerate(surface):
            if not v == 1:
                continue
            
            # A
            if i+9 < 64 and surface[i+1] == 1 and surface[i+8] == 1 and surface[i+9] == 1:
                print('A')
                break
            
            # B
            if i+24 < 64 and surface[i+24] == 1:
                print('B')
                break
            
            # C
            if surface[i+3] == 1:
                print('C')
                break
            
            # D
            if i+15 < 64 and surface[i+15] == 1:
                print('D')
                break
            
            # E
            if i+10 < 64 and surface[i+10] == 1:
                print('E')
                break
            
            # F
            if i+17 < 64 and surface[i+17] == 1:
                print('F')
                break
            
            # G
            if surface[i+1] == 1 and surface[i+7] == 1 and surface[i+8] == 1:
                print('G')
                break
            
        
        try:
            input()
            line = input()
        except EOFError:
            break
    

if __name__ == "__main__":
    solve()



Measured memory_bytes: 5608
#include <stdio.h>
int main(void){
int a,b;
scanf("%d %d",&a,&b);
if(a==2||b==2){printf("No");}
else if(a==12||a==11){printf("No");}
else if((a==1||a==3||a==5||a==7||a==8||a==10)&&(b==3||b==5||b==7||b==8||b==10||b==12)){printf("Yes");}
else if((a==4||a==6||a==9)&&(b==4||b==6||b==9||b==11)){printf("Yes");}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt=0;
    for(int i=0; i<n; i++){
        if((double)a[i] >= (double)sum/(4*m)){
            cnt++;
        }
    }
    if(cnt >= m ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		
		Scanner input = new Scanner(System.in);
		long l = input.nextInt();
        long r = input.nextInt();
        long remain = (long)(2 * Math.pow(10,9)) * 2;
        for (long i = l; i < r; i++) {
            for (long j = i + 1; j <= r; j++) {
                if(i*j %2019 < remain)
                    remain = i*j %2019;
                if(remain == 0)
                    break;
            }
            if(remain == 0)
                break;
        }
		System.out.println(remain);
	}
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
#define N 100010
int main(){
    double x;cin>>x;
    int candid = floor(x/1.08);
    if(floor(candid*1.08)==x){co(candid);return 0;}
    candid = ceil(x/1.08);
    if(floor(candid*1.08)==x){co(candid);return 0;}
    co(":(");
}


Measured memory_bytes: 256
n=int(input())

F=[list(map(int,input().split())) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]

ans=(10**9)*(-1)
for i in range(1,2**10):
    cnt=[0]*n
    for j in range(10):
        if i>>j &1:
            for x in range(n):
                if F[x][j]==1:
                    cnt[x]+=1
    tmp=0
    for k in range(n):
        tmp+=P[k][cnt[k]]
    ans=max(ans,tmp)

print(ans)





Measured memory_bytes: 74020
#include<stdio.h>
#include<stdlib.h>
#define MAX 500000
#define INF 1000000000

void k_tmerge(int *,int,int,int);
void tmergesort(int *,int,int);

int count;


void tmergesort(int A[],int left,int right)
{
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    tmergesort(A,left,mid);
    tmergesort(A,mid,right);
    k_tmerge(A,left,mid,right);
  }
}

void k_tmerge(int *A,int left,int mid,int right)
{
  int i,k,j,n1=0,n2=0;
  int *L,*R;

  n1 = mid - left;
  n2 = right - mid;

  L = (int *)malloc(sizeof(int)*(n1+1));
  R = (int *)malloc(sizeof(int)*(n2+1));

  for(i = 0;i <= n1-1;i++){
    L[i] = A[left + i];
  }

  for(j = 0;j <= n2-1;j++){
    R[j] = A[mid + j];
  }

  L[n1] = INF;
  R[n2] = INF;
  i = 0;
  j = 0;

  for(k = left;k <= right-1;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      count++;
    }
    else {
      A[k] = R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

int main()
{
  int n,i;
  int A[MAX];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  tmergesort(A,0,n);

  for(i = 0;i < n;i++){
    if( i > 0 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastIO fastIO = new FastIO();
        String a, b;
        int ans = 0;
        a = fastIO.read();
        b = fastIO.read();

        for(int i=0;i<a.length();i++)
        {
            if(a.charAt(i) == b.charAt(i))
                ++ans;
        }
        System.out.println(ans);
    }

    private static class FastIO {
        private StringTokenizer stringTokenizer;
        private BufferedReader bufferedReader;

        public FastIO() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            stringTokenizer = null;
        }

        public String read() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return stringTokenizer.nextToken();
        }

        public int readInt() {
            return Integer.parseInt(read());
        }

        public long readLong() {
            return Long.parseLong(read());
        }
    }
}

Measured memory_bytes: 22996
/*
 *  author : Atul Anand   
 *  created on : Thu Apr 02 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int p[] = new int[n];
        read(p, n);
        int ans = 0;
        for(int i = 1; i+1 < n; i++){
            int min = Math.min(p[i-1], Math.min(p[i], p[i+1]));
            int max = Math.max(p[i-1], Math.max(p[i], p[i+1]));
            if(min != p[i] && max != p[i]){
                ans++;
            }
        }
        println(ans);
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21204
// https://atcoder.jp/contests/abc078/tasks/abc078_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y;
    cin >> x >> y;
    cout << (1900 * y + 100 * (x - y)) * (1LL << y) << endl;

    return 0;
}


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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

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

    if(N==M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 2  # type: int

def solve(N: int, a: "List[int]"):
    def isodd(ai: int):
        flag = False
        hoge = N // ai

        while True:
            if hoge == 1:
                break
            if ans[ai * hoge -1]:
                flag = not flag
            hoge = hoge - 1
        return flag

    sum = 0
    num = []
    ans = [0] * N

    for i in reversed(range(1, N+1)):
        odd = isodd(i)
        write = not (odd == a[i-1])

        if write:
            sum = sum + 1
            num.append(i)
            ans[i-1] = 1

    print(sum)
    if sum != 0:
        print(' '.join(map(str, num)))
    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

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

typedef long long ll;
#define fori(n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair

ll power(ll base,ll e)
{
    ll answer=1;
    //ll e=1000000005;
    while(e)
    {
        if(e%2==1)
        {
            answer*=base;
        }
        base*=base;
       // base%=mod;
        e/=2;
       // answer%=mod;
    }
    return answer;
}

void mergearr(ll arr[], ll l,ll m, ll r)
{
    ll i,j,k;
    ll n1= m-l+1;
    ll n2 = r-m;
    ll L[n1],R[n2];
    for(i=0;i<n1;i++)
        L[i]=arr[l+i];
    for(i=0;i<n2;i++)
        R[i]=arr[m+1+i];

    i=0; j=0; k=l;
    while(i<n1 && j<n2)
    {
        if(L[i]<=R[j])
        {
            arr[k]=L[i];
            i++;
        }
        else
        {
            arr[k]=R[j];
            j++;
        }
        k++;
    }
    while(i<n1)
    {
        arr[k]=L[i]; i++; k++;
    }
    while(j<n2)
    {
        arr[k]=R[j]; j++; k++;
    }
}
void mergesort(ll arr[],ll l, ll r)
{
    if(l<r)
    {
        ll m = l+(r-l)/2;
        mergesort(arr,l,m);
        mergesort(arr,m+1,r);
        mergearr(arr,l,m,r);
    }
}


void sieveprimes(ll n)
{
        bool prime[n+1];
        memset(prime,true,sizeof(prime));

        for(ll i=2;i*i<=n;i++)
        {
            if(prime[i]==true)
            {
                for(ll j=i*i;j<=n;j+=i)
                {
                    prime[j]=false;
                }

            }

        }

        /*for (int p=2; p<=n; p++)
           if (prime[p])
              cout << p << " ";*/

    }


int main()
{

    ll n;
    cin>>n;
    ll a[n];
    fori(n)
    {
        cin>>a[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ans=ans^a[i];
    }
    fori(n)
    {
        a[i]=ans^a[i];
    }
    fori(n)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";

}




Measured memory_bytes: 5160
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int p,q,r;
    cin>>p>>q>>r;
    cout<<p+q+r-max(p,max(q,r))<<endl;


    return 0;
}



Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import sys
N = int(sys.stdin.readline())
line = sys.stdin.readline()
A = [ int(i) for i in line.strip().split() ]
min = 999999
for a in A:
    cnt = 0
    while(min > cnt):
        if a%2 == 1:
            min = cnt
            break
        else:
            a = a/2
            cnt += 1
print(cnt)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var str1 = ReadLine();
        var str2 = ReadLine();
        var res = 3L;
        for(var i = 0; i < num-1; i++)
        {
            if (i > 1 && str1[i] == str1[i + 1] && str1[i - 1] == str1[i - 2])
                res *= 3;
            else if (str1[i] == str1[i + 1])
                res *= 2;
            else if ((i==0&&str1[1]==str2[1])||(i>0&&str1[i]!=str1[i-1]&&str1[i+1]==str2[i+1]))
                res *= 2;
            res %= MOD;
        }
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 11220
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int> logs(n);
	for (auto& log : logs) cin >> log;
	int min = 1, max = 1000000000;
	while (min < max) {
		const auto mid = (min + max) >> 1;
		int count_rest = k;
		for (auto log : logs) {
			if (log > mid) {
				count_rest -= (log - 1) / mid;
			}
			if (count_rest < 0) break;
		}
		if (count_rest < 0) {
			min = mid + 1;
		}
		else {
			max = mid;
		}
	}
	cout << max << '\n';
}

Measured memory_bytes: 3892
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

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


signed main(){

	string s;
	ll k;
	cin >> s >> k;
	ll n = s.size(),ans = 0,memo = 1;
	ll pre_cnt = 1,suf_cnt = 1;



	



	

	rep(i,1,n){
		if(s[0] == s[i] && s[i] == s[i-1]) pre_cnt++;
		else break;
	}

	repr(i,0,n-1){
		if(s[n-1] == s[i] && s[i] == s[i+1]) suf_cnt++;
		else break;
	}

	
	if(pre_cnt == n){
		cout << k*n / 2 << endl;
		return 0;
	}

	rep(i,pre_cnt,n-suf_cnt){
		if(s[i] != s[i+1]){
			ans += memo / 2;
			memo = 1;
		}
		else memo++;
	}
	
	ans += memo / 2;
	ans *= k;
	
	if(s[0] == s[n-1]) ans += (k-1)*((pre_cnt+suf_cnt)/2);
	else ans += (k-1)*(pre_cnt/2+suf_cnt/2);
	ans += pre_cnt/2 + suf_cnt/2;

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();
		String ans = "No";
		if (s.length() >= 4) {
			if ("YAKI".equals(s.substring(0, 4)))
				ans = "Yes";
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21204
n = int(input())
s = input()
t = ''
abc = [chr(i) for i in range(65, 65+26)]
for i in s:
  m = abc.index(i)
  if m+n <= 25:
    t += abc[m+n]
  else:
    t += abc[m+n-26]
print(t)

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

using namespace std ;

#define N 1000010
#define ll long long



const ll mod = 1e9 + 7 ;
ll fac[ N ] ,ifac[ N ] ;
ll n , m ;
ll q[ N ] , cnt = 0 ;
map<int,int> mp ;

ll power( ll a , ll b ) {
	ll ans = 1 , base = a ; 
	while( b ) {
		if( b&1 ) ans = ( ans * base ) % mod ;
		base = ( base * base ) % mod ;
		b >>= 1 ;
	}
	return ans ;
}

ll C( ll n , ll m ) {
	return fac[ m ] * ifac[ n ] % mod * ifac[ m - n ] % mod ;
}

int main() {
	scanf( "%lld%lld" , &n , &m ) ;
	fac[ 0 ] = 1 ; 
	for( int i = 1 ; i < N ; i ++ ) fac[ i ] = ( fac[ i - 1 ] * i ) % mod ;
	for( int i = 0 ; i < N ; i ++ ) ifac[ i ] = power( fac[ i ] , mod - 2 ) % mod ;
	ll ln = m , tmp = 2 ; 
	while( ln != 1 && tmp * tmp <= ln ) {
		if( ln % tmp == 0 ) {
			mp[ tmp ] ++ ;
			if( mp[ tmp ] == 1 ) q[ ++ cnt ] = tmp ;
			ln /= tmp ;
	 	}else tmp ++ ;
	}
	if( ln != 1 ) {
		mp[ ln ] ++ ;
		if( mp[ ln ] == 1 ) q[ ++ cnt ] = ln ;
	} 
	ll ans = 1 ;
	for( int i = 1 ; i <= cnt ; i ++ ) {
		ans = ans * C( n - 1 , mp[ q[ i ] ] + n - 1 ) % mod ;
	}
	printf( "%lld\n" , ans ) ;
	return 0 ;
}

Measured memory_bytes: 17536
function Main(inputs) {
	const inputlines = inputs.split("\n");
 	const testcase = inputlines[0];
  
  	let counts = ["AC", "WA", "TLE", "RE"];
  	counts["AC"] = counts["WA"] = counts["TLE"] = counts["RE"] = 0;
  
	for(let i=1;i <= testcase;i++){
  		let key = inputlines[i];
  		counts[key] = (counts[key] != 0) ? counts[key] + 1 : 1;
	}
  
  	console.log("AC x "+counts['AC']);
	console.log("WA x "+counts['WA']);
  	console.log("TLE x "+counts['TLE']);
  	console.log("RE x "+counts['RE']);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37196
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000000000
using namespace std;


int main(void){
  ll n,m,p;
  cin >> n >> m >> p;

  vector<vector<pair<ll,ll> > > list(n+1);
  vector<vector<int> > list2(n+1);
  rep(i,m){
	ll a,b,c;
	cin >> a >> b >> c;
	list[a].emplace_back(b,c-p);
	list2[b].push_back(a);
  }

  
  vector<bool> flag(n+1,false),reach(n+1,false);
  flag[n] = true;
  rep(i,n){
	rep(j,n){
	  //cout << "size:" << list2[j+1].size() << endl;
	  if(!flag[j+1]) continue;
	  for(int to : list2[j+1]){
		//cout << "goto" << j+1 << "->" << to << endl;
		flag[to] = true;
	  }
	}
  }
  //rep(i,n)cout << flag[i+1] << " ";
  //cout << endl;  
  vector<ll> cur(n+1,-MAX),tmp(n+1,0);
  
  cur[1] = 0;
  reach[1] = true;
  ll ans;

  rep(i,n){
	rep(j,n){
	  if(!reach[j+1]) continue;
	  rep(k,list[j+1].size()){
		ll to = list[j+1][k].first,cost = list[j+1][k].second;
	    reach[to] = true;
		if(cur[to] < cur[j+1]+cost){
		  cur[to] = cur[j+1]+cost;
		}
	  }
	}
	//rep(j,n) cout << cur[j+1] << " ";
	//cout << endl;
	if(i == n-2){
	  ans = cur[n];
	  tmp = cur;
	}
	if(i == n-1){
	  rep(j,n){
		if(tmp[j+1] < cur[j+1] && flag[j+1]) cur[n] = ans+1;
	  }
	}
  }

  if(ans < cur[n]) cout << -1 << endl;
  else cout << max(ans,0LL) << endl;

  return 0;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
if 3 <= n and 3 <= m:
    print((n-2)*(m-2))
elif n == 1 or m == 1:
    if (n,m) == (1,1):
        print(1)
    else:
        print(max(n-2,m-2))
else:
    print(0)



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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int N;
    string S;
    cin >> N >> S;

    int x = 0;
    int x_max = 0;
    for (int i = 0; i < N; i++) {
        if(S[i] == 'I') {
            x++;
            if (x > x_max) {
                x_max = x;
            }
        } else if (S[i] == 'D') {
            x--;
        }
    }
    cout << x_max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    REP(i,n){
        int x;
        cin >> x;
        ans += 2 * min(x, k - x);
    }
    cout << ans << endl;

    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, m, l;
	int i, j, k;
	int a[100][100], b[100][100];
	
	scanf("%d %d %d", &n, &m, &l);
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			scanf("%d", &b[i][j]);
		}
	}
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			long long sum = 0;
			
			for (k = 0; k < m; k++) sum += a[i][k] * b[k][j];
			
			printf("%s%lld", j ? " " : "", sum);
		}
		puts("");
	}
	
	return 0;
}



Measured memory_bytes: 2104
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = 10**10
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(1, n):
    dp[i] = min(dp[j] + abs(h[j] - h[i]) for j in range(max(0, i - k), i))

print(dp[n - 1])


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  set<ll> s;
  ll N;
  cin>>N;
  rep(i,N){
    ll x;
    cin>>x;
    s.insert(x);
  }
  if (s.size() == N){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

void swap(long *a, long *b){
  long tmp = *a;
  *a = *b;
  *b = tmp;
}

int main(){
  long n;
  cin >> n;
  long ans = 0;
  long u,v;
  rep(i,n-1){
    cin >> u >> v;
    if(u>v)swap(&u,&v);
    ans += (i+1)*(n-i) - u*(n-v+1);
  }
  ans += n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
from collections import*
H,*A=open(0)
H,W,K=map(int,H.split())
*A,=map(list,A)
for i,a in enumerate(A):
	if'S'in a:j=a.index('S');Q=deque([(0,i,j)])
d=1e9
while Q:
	c,i,j=Q.popleft();d=min(d,i,j,~i+H,~j+W)
	if c<K:
		for h,w in((i+1,j),(i,j+1),(i-1,j),(i,j-1)):
			if H>h>-1<w<W and'.'==A[h][w]:A[h][w]=0;Q+=(c+1,h,w),
print(1--d//K)

Measured memory_bytes: 102364
#include <iostream>
using namespace std;
int main(){
  int a, b, k, i, j=0;
  cin >> a >> b >> k;
  for(i=a;i>0;i--){
  	if(a%i==0 && b%i==0) j++;
    if(j==k) break;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif
}

void solve() {
	int A, B, C, X, Y;
	scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);
	C *= 2;
	int share = min(X, Y);
	int value = min(C * share, (A + B) * share);
	share = max(X, Y) - share;
	if (X < Y)
		value += min(C * share, B * share);
	if (X > Y)
		value += min(C * share, A * share);
	printf("%d\n", value);
}

Measured memory_bytes: 128
// 荒井テスト

#include <iostream>
#include <vector>

using namespace std;

struct UnionFind
{
    // par[i]はiの親の番号
    vector<int> par;
    // 根ノードiに含まれるノードの数
    vector<int> sizes;

    // 最初は全てが根、サイズは0
    UnionFind(int N) : par(N), sizes(N)
    {
        for (int i = 0; i < N; i++)
        {
            par[i] = i;
            sizes[i] = 0;
        }
    }

    // xが属する木の根を再帰で得る
    int find(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }

    // データ xが含まれる木のサイズを返す
    int size(int x)
    {
        return sizes[find(x)];
    }

    // データxとデータyが同じグループにあるか判定する
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    // 同じ親を持つならばマージする
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (size(x) < size(y))
        {
            par[x] = y;
            sizes[y] += sizes[x] + 1;
            sizes[x] = 0;
        }
        else
        {
            par[y] = x;
            sizes[x] += sizes[y] + 1;
            sizes[y] = 0;
        }
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<unsigned int> A(M);
    vector<unsigned int> B(M);
    vector<long long int> result(M);
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    UnionFind UF(N);
    result[M - 1] = (long long)N * (N - 1) / 2;
    for (int i = M - 1; i > 0; i--)
    {
        long long int size_a;
        long long int size_b;
        if (!UF.same(A[i], B[i]))
        {
            size_a = UF.size(A[i]) + 1;
            size_b = UF.size(B[i]) + 1;
        }
        else
        {
            size_a = 0;
            size_b = 0;
        }

        UF.unite(A[i], B[i]);
        result[i - 1] = result[i] - size_a * size_b;
    }
    for (int i = 0; i < M; i++)
        cout << result[i] << endl;

    return 0;
}

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

string s;
int n, cnt;

int main(){
    cin >> n >> s;
    for(int i = 0; i < 1000;i++){
        int key[3];
        key[0] = i / 100;
        key[1] = i / 10 % 10;
        key[2] = i % 10;
        int f = 0;
        for(int j = 0; j < n; j++){
            if(s[j] == ('0' + key[f])) 
                f++;
            if(f == 3)
                break;
        }
        if(f==3)
            cnt++;
    }
    cout << cnt;
}

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

//temmplate------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define ZERO(a) memset(a, 0, sizeof(a))
typedef long long ll;
//------template

int main(){
    ll H;
    cin >> H;
    ll count = 0;
    ll num = 1;
    while (H > 0){
        if (H%2 == 1){
            H = (H-1)/2;
        } else {
            H = H/2;
        }
        count+= num;
        num *= 2;
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long long dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; ++i) {
        int jump1 = abs(a[i] - a[i - 1]);
        int jump2 = abs(a[i] - a[i - 2]);
        if (dp[i - 1] + jump1 < jump2 + dp[i - 2]) {
            dp[i] = dp[i - 1] + jump1;
        } else {
            dp[i] = dp[i - 2] + jump2;
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}




Measured memory_bytes: 1408