akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := a * b

	if c%2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}

}


Measured memory_bytes: 640
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 0

for i in range(N+1):
    if i%2 != 0:
        A = make_divisors(i)
        if len(A) == 8:
            ans = ans+1
print(ans)

Measured memory_bytes: 3188
import math
n=int(input())
a=[]
for x in range(n):
  b=list(map(int,input().split()))
  a.append(b)
  

ans=0
nn=math.factorial(n)*2/n
for y in range(0,n-1):
  for z in range(y+1,n):
    p=a[y][0]
    q=a[y][1]
    s=a[z][0]
    t=a[z][1]
    u=(p-s)*(p-s)+(q-t)*(q-t)
    r=math.sqrt(u)
    
    ans+=r*nn
    
print(ans/math.factorial(n))

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    string s,t;
    int a, b;
    string u;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(u == s)
    {
        cout << a-1 << " " << b << endl;
    }
    else
    {
        cout << a << " " << b-1 << endl;
    }
    
//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1e9 + 7;
int main() {
    llint N, K;
    cin >> N;
    vector<llint> p(N + 1);
    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        p[x] = i;
    }
    set<int> s;
    s.insert(-1);
    s.insert(N);
    llint rez = 0;
    for(llint i = N; i >= 1; i--) {
        auto it = s.lower_bound(p[i]);
        llint prviVeci = *it;
        it++;
        llint drugiVeci;
        if(prviVeci == N)
            drugiVeci = N;
        else
            drugiVeci = *it;
        it--; it--;
        llint prviManji = *it;
        llint drugiManji;
        it--;
        if(prviManji == -1)
            drugiManji = -1;
        else 
            drugiManji = *it;
        rez += i * (p[i] - prviManji) * (drugiVeci - prviVeci);
        rez += i * (prviVeci - p[i]) * (prviManji - drugiManji);
        //cout << i << " " << drugiManji << " " << prviManji << " " << prviVeci << " " << drugiVeci << " " << rez << endl;
        s.insert(p[i]);
    }
    cout << rez;
}

Measured memory_bytes: 5760
#A - Wanna go back home
S = list(input())

N = S.count('N')
E = S.count('E')
W = S.count('W')
s = S.count('S')

if ((N>0 and s>0) and ((E>0 and W>0) or (E == W == 0))) or ((N == s == 0) and ((E>0 and W>0) or (E == W == 0))):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N, M;
int a[MAX_N+1], b[MAX_N+1];
int c[MAX_N+1];

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

  cin >> N >> M;
  rep(i, M) cin >> a[i] >> b[i];

  rep(i, M) {
      c[a[i]]++;
      c[b[i]]++;
  }

  rep(i, 1, N) {
      if (c[i]%2 != 0) {
          cout << "NO" << endl;
          return 0;
      }
  }

  cout << "YES" << endl;
  return 0;
}


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

int main(){
	int a,b,c;
  	cin >> a >> b >> c;
  	
  	if( a+b+c >= 22){
    	cout << "bust" << endl;	
    }
  	if( a+b+c <= 21){
    	cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//copy and fix 
//from https://drken1215.hatenablog.com/entry/2018/09/06/020200
template <class T> struct BIT {
    vector<T> dat;
    T UNITY_SUM = 0;                        // to be set
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, 0) { }
    void init(int n) { dat.sssign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, T x) {
        dat[a] = dat[a] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline T sum(int a) {
        T res = UNITY_SUM;
        for (int i = a; i > 0; i--)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int N, M, Q;
typedef pair<int,int> pint;
typedef pair<pint,int> ipint;
vector<ipint> ins;
vector<int> alts;

bool cmp(ipint a, ipint b) {
    return make_pair(a.first.second, a.second) < make_pair(b.first.second, b.second);
}

int main() {
    // 入力受け取り、区間終点ソート、座標圧縮
    cin >> N >> M >> Q;
    ins.resize(M + Q);
    alts.clear();
    for (int i = 0; i < M + Q; ++i) {
        cin >> ins[i].first.first >> ins[i].first.second;
        ++ins[i].first.second;
        if (i < M) ins[i].second = -1; else ins[i].second = i - M;
        alts.push_back(ins[i].first.first), alts.push_back(ins[i].first.second);
    }
    sort(alts.begin(), alts.end());
    alts.erase(unique(alts.begin(), alts.end()), alts.end());
    sort(ins.begin(), ins.end(), cmp);
    
    // 座標圧縮
    for (int i = 0; i < M + Q; ++i) {
        int left = lower_bound(alts.begin(), alts.end(), ins[i].first.first) - alts.begin();
        int right = lower_bound(alts.begin(), alts.end(), ins[i].first.second) - alts.begin();
        ins[i].first.first = left + 1;
        ins[i].first.second = right + 1;
    }

    // 平面走査
    BIT<int> bit( (M+Q)*2 + 10 );
    vector<int> res(Q);
    for (int i = 0; i < M + Q; ++i) {
        if (ins[i].second == -1) bit.add(ins[i].first.first, 1);
        else res[ins[i].second] = bit.sum(ins[i].first.first, ins[i].first.second);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main(int argc, char* argv[])
{
    int x, i;
    vector<int> vec;

    i=0;
    while(cin >> x)
    {
        if(x==0) break;
        vec.push_back(x);

    }
    for (vector<int>::iterator it = vec.begin(); it != vec.end(); it++)
    {
        i++;
        cout << "Case " << i << ": " << *it << endl;


    }

    return 0;
}



Measured memory_bytes: 3180
#include <stdio.h>
#include <math.h>


main(){
  int n, i, j, k, p, count;
  int data[100000];
  k=1;
  data[0]=2;
  for(i=3;i<1000000;i+=2){
    p=0;
    if(i%2==0) continue;
    for(j=3;j<=(int)sqrt(i);j+=2){
      if(i%j==0){
	p=1;
	break;
      }
    }
    if(p==1) continue;
    data[k]=i;
    k++;
  }

  data[k]=-1;
   while(1){
    count=0;
    if(scanf("%d", &n)==EOF) break;
    for(i=0;i<100000;i++){
      if(data[i]>n) break;
      if(data[i]==-1) break;
      count++;
    }
    printf("%d\n", count);
    }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    string a,b;
    cin >> a >> b;

    if(a.size() < b.size()){
        cout << "LESS" << endl;
        return 0;
    }
    if(a.size() > b.size()){
        cout << "GREATER" << endl;
        return 0;
    }

    rep(i, a.size()){
        if(a[i] < b[i]){
            cout << "LESS" << endl;
            return 0;
        }
        if(a[i] > b[i]){
            cout << "GREATER" << endl;
            return 0;
        }
    }

    cout << "EQUAL" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
int main(){
    ios;
    int k, a, b;
    cin >> k >> a >> b;
    bool flag = false;
    for( int i = a; i <= b; i++){
        if(i % k == 0) flag = true;
    }
    cout << ((flag)? "OK" : "NG");
    
    
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,y,maxn,minn;
	cin>>a>>b>>c>>x>>y;
	if(x>y) minn=y,maxn=x;
	else minn=x,maxn=y;
	int sum[maxn+2];
	sum[0]=x*a+y*b;
	for(int i=1;i<=minn;i++)
		sum[i]=2*i*c+(y-i)*b+(x-i)*a;
	for(int i=minn+1;i<=maxn;i++)
		if(y>x) sum[i]=2*i*c+(y-i)*b;
		else sum[i]=2*i*c+(x-i)*a;
	sort(sum,sum+maxn+1);
	cout<<sum[0];
	return 0;
}

Measured memory_bytes: 640
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
leaves = []
for i in 0..N do
  leaves.push(lines[1][i])
end

max_bi = -1  # max bification
for i in 0..N do
  max_bi += leaves[i]
end

def max_nodes(leaves, max_bi)
  remain_bi = max_bi
  nodes = [1]       #always one node with depth 0
  for i in 0..N-1 do
    num_fin = leaves[i]
    if remain_bi >= nodes[i] - num_fin then
      num_bi = nodes[i] - num_fin
      remain_bi -= nodes[i] - num_fin
      num_sin = 0
    else
      num_bi = remain_bi
      remain_bi = 0
      num_sin = nodes[i] - num_fin - num_bi
    end
    next_nodes = num_bi * 2 + num_sin
    nodes.push(next_nodes)
  end
  for i in 0..N do
    if nodes[i] < leaves[i] then
      return [-1]
    end
  end
  return nodes
end
  
num_nodes = max_nodes(leaves, max_bi)
ans = 0
for i in 0..(num_nodes.length-1) do
  ans += num_nodes[i]
end
print ans

Measured memory_bytes: 982460
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6+5;
int main()
{
	sync;
	ll n, k;
	cin >> n >> k;
	ll arr[n];
	input(arr, n);
	ll low = 1, high = 1e9, ans = *max_element(arr, arr + n);
	while(low <= high)
	{
		ll mid = (low + high) /2;
		ll cuts = 0;
		for(ll i = 0 ; i < n ; i ++)
			if(arr[i] > mid)
				 cuts += (arr[i] / mid + (arr[i] % mid > 0) - 1);
		if(cuts <= k)
		{
			ans = mid;
			high = mid - 1;
		}
		else
			low = mid + 1;
	}
	cout << ans;
}

Measured memory_bytes: 5176
N = gets.to_i
MOD = 10**9+7
col = [0]*(3*10**5)
dp = [0]*(N+1)
dp[0] = 1
pc = 0
N.times do |i|
  c = gets.to_i
  if c == pc
    dp[i+1] = dp[i]
  else
    dp[i+1] = dp[i] + col[c]
    col[c] += dp[i]
    dp[i+1] %= MOD
    col[c] %= MOD
  end
  pc = c
end
p dp[N]

Measured memory_bytes: 7932
#include<stdio.h> 
#define MAX 100005 
#define NIL -1 
struct Node_struct{int p, s, d, l, r;}; 
typedef struct Node_struct Node; 
Node T[MAX]; 
int D[MAX]; 
int H[MAX];

void print(int u){ 
int i, c; 
printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", u, T[u].p, T[u].s, T[u].d, D[u], H[u]); 

if(T[u].p==NIL) printf("root\n"); 
else if(T[u].l==NIL && T[u].r==NIL) printf("leaf\n"); 
else printf("internal node\n"); 

} 

void calcDepth(int u, int p){ 
    if(u==NIL) return;
    D[u] = p; 
    calcDepth(T[u].l, p+1); 
    calcDepth(T[u].r, p+1); 
} 

int calcHeight(int u){
    int h1=0, h2=0;
    if(T[u].l!=NIL) h1=calcHeight(T[u].l)+1;
    if(T[u].r!=NIL) h2=calcHeight(T[u].r)+1;
    if(h1>h2) return H[u]=h1;
    else return H[u]=h2;
}

int main(){ 
int i, j, k; 
int n; 
int id, child_l, child_r; 
int root = NIL; 
scanf("%d", &n); 
for(i=0; i<n; i++){
    T[i].p = T[i].l = T[i].r = T[i].s = NIL; 
    T[i].d=0;
}

for(i=0; i<n; i++){ 
    scanf("%d%d%d", &id, &child_l, &child_r);
    if(child_l!=NIL){
        T[id].d++;
        T[id].l=child_l;
        T[child_l].p=id;
    }
    if(child_r!=NIL){
        T[id].d++;
        T[child_r].p=id;
        T[id].r=child_r;
    }

    T[child_l].s=child_r;
    T[child_r].s=child_l;
} 

//(find the root) 
for(i=0; i<n; i++){ 
if(T[i].p == -1) root = i; 
} 

//(find depth of each node) 
calcDepth(root, 0); 
calcHeight(root);

//(output) 
for(i=0; i<n; i++) print(i); 

return 0; 
}



Measured memory_bytes: 2108
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec2<ll> dist;

void WarshallFloyd(ll V){
	rep(k, V) rep(i, V) rep(j, V) chmin(dist[i][j], dist[i][k]+dist[k][j]);
}

int main(void){
	ll n;
	cin >> n;
	dist.resize(n);
	rep(i, n) dist[i].assign(n, LINF);
	ll sum = 0;
	rep(i, n) rep(j, n) cin >> dist[i][j];
	Vec2<bool> flg(n, VecB(n, true));

	rep(k, n) rep(i, n) rep(j, n){
		if(dist[i][j] > dist[i][k]+dist[k][j]){
			co(-1);
			return 0;
		}else if(i != k && j != k && dist[i][j] == dist[i][k]+dist[k][j]) flg[i][j] = false;
	}

	ll ans = 0;
	rep(i, n) rep(j, n){
		if(flg[i][j]) ans += dist[i][j];
	}
	co(ans/2);

	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; i < (n); i++)

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  int n,m;
  cin>>n>>m;
  int v=n+m-1;
  vector<int> G[n];
  vector<int> rG[n];
  vector<int> js(n,0);
  for(int i=0;i<v;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    rG[b].push_back(a);
    js[b]++;
  }
  stack<int> st;
  int x;
  for(int i=0;i<n;i++)if(js[i]==0){
    st.push(i);
    x=i;
    break;
  }
  vector<int> tps;
  while(st.size()){
    int np=st.top();
    st.pop();
    tps.push_back(np);
    for(int i=0;i<G[np].size();i++){
      js[G[np][i]]--;
      if(js[G[np][i]]==0)st.push(G[np][i]);
    }
  }

  vector<int> btps(n);
  for(int i=0;i<n;i++)btps[tps[i]]=i;

  for(int i=0;i<n;i++){
    if(i==x)cout<<0<<endl;
    else{
      int id;
      int tmp=-1;
      for(int j=0;j<rG[i].size();j++){
        if(tmp<btps[rG[i][j]]){
          tmp=btps[rG[i][j]];
          id=rG[i][j];
        }
      }
      cout<<id+1<<endl;
    }
  }

}


Measured memory_bytes: 14200
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

/* gcd */
template<typename T>
T gcd(T a,T b)
{
	if(a==0 || b==0)return 0;
	T r;
	while(1)
	{
		r=a%b;
		if(r==0)break;
		a=b;
		b=r;
	}
	return b;
}

/* lcm */
template<typename T>
T lcm(T a,T b)
{
	if(a==0 || b==0)return 0;
	return a*b/gcd(a,b);
}

int main()
{
	lint N,M;
	lint G;
	string S,T;
	
	cin >> N >> M;
	cin >> S >> T;
	
	G=gcd(N,M);
	for(lint i=0;i<G;i++)
	{
		if(S[i*N/G]!=T[i*M/G])
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << lcm(N,M) << endl;
	return 0;
}



Measured memory_bytes: 512
import java.util.*;

class Main{
	public static void main(String[] args) throws Exception{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		int[] arr = new int[1000];
		for(int i = 1; i < 1000; i++) {
			arr[i] = arr[i-1]+i;
		}
		System.out.println(arr[b-a]-b);
	}
}


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

int64_t f(int64_t n, int64_t x){
  if(n == -1)
    return 0;
  else
    return n / x + 1;
}

int main(){
  int64_t a,b,x,count = 0;
  cin >> a >> b >> x;
  cout << f(b, x) - f(a - 1, x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int main(){
    int N,M; cin >> N >> M;
    ll dp[100010]; fill(dp,dp+100010,0);
    vector<int> v(M);

    int can[100010]; fill(can,can+100010,1);
    //int in = 0;
    for (int i = 0; i < M; i++){
        cin >> v[i];
        can[v[i]] = 0;
    }
    for (int i = 1; i <= N; i++){
        if (i == 1 && can[i]){
            dp[i] = 1;
            continue;
        }
        if (i == 2 && can[i]){
            dp[i] = dp[i-1] + 1;
            continue;
        }
        if (can[i] == 0){
            continue;
        }
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= MOD;
    }
    cout << dp[N] << endl;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,cn;
  cin >> n >> cn;
  vector<vector<int32>> d(cn, vector<int32>(cn));
  REP(i,cn)REP(j,cn)cin >> d[i][j];
  vector<vector<int32>> c(n,vector<int32>(n));
  REP(i,n)REP(j,n){
    cin >> c[i][j];
    --c[i][j];
  }
  vector<vector<int32>> dsum(3,vector<int32>(cn,0));
  REP(nc,cn){
    REP(i,n)REP(j,n){
      dsum[(i+j)%3][nc] += d[c[i][j]][nc];
    }
  }
  int32 ans = INF;
  REP(i,cn){
    REP(j,cn){
      if(i == j)continue;
      REP(k,cn){
        if(i == k || j == k)continue;
        ans = min(ans, dsum[0][i] + dsum[1][j] + dsum[2][k]);
      }
    }
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	int X, Y;
	cin >> X >> Y;
	for(int i=0; i<=X; ++i){
		if(i*2 + (X-i)*4 == Y){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define M 1000005


struct node{
     int v;
     int w;
     int next;
     int cost;
}e[M];

int num=0;
int head[M],mark[M],ans[M],tp[M];
long long dist[M],dist1[M];
void init()
{
    memset(head,-1,sizeof(head));
    memset(mark,false,sizeof(mark));
    memset(ans,1,sizeof(ans));
    memset(dist,1,sizeof(dist));
    num=0;
}

void add(int aa,int bb,int t, int cc)
{
    e[num].v=bb;
    e[num].w=t;
    e[num].cost=cc;
    e[num].next=head[aa];
    head[aa]=num;
    num++;
}

void SPFA(int x)
{
     queue<int> q;
     q.push(x);
     mark[x]=true;
     dist[x]=0;
     while(!q.empty())
     {
          int tmp=q.front();
          q.pop();
          mark[tmp]=false;
          for(int i=head[tmp];i!=-1;i=e[i].next)
          {
                if(dist[e[i].v]==dist[tmp]+e[i].w && e[i].cost < ans[e[i].v])
                       ans[e[i].v]=e[i].cost;
                if(dist[e[i].v]>dist[tmp]+e[i].w)
                {
                         dist[e[i].v]=dist[tmp]+e[i].w;
                         ans[e[i].v]=e[i].cost;
                         if(!mark[e[i].v])
                         {
                               q.push(e[i].v);
                               mark[e[i].v]=true;
                         }
                }
          }
     }
}

int u[M],v[M], d[M], c[M];

int main()
{
    int n,m,x;
    while(~scanf("%d%d",&n,&m) && n+m)
    {
        int sum=0;
        init();
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d%d",&u[i],&v[i],&d[i], &c[i]);
            add(u[i],v[i],d[i],c[i]);
            add(v[i],u[i],d[i],c[i]);
        }
        SPFA(1);
        for(int i=2;i<=n;i++) sum+=ans[i];
  
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 23176
#include <stdio.h>

int main(void)
{
	int n;
	int ame[3][101];
	int get[3][101];
	int i,j;
	
	scanf("%d", &n);
	//配列の初期化
	for(i=0;i<=2;i++){
		for(j=0;j<=n;j++){
			ame[i][j]=0;
			get[i][j]=0;
		}
	}
	
	
	for(i=1;i<=2;i++){
		for(j=1;j<=n;j++){
			scanf("%d", &ame[i][j]);
		}
	}
	
	for(i=1;i<=2;i++){
		for(j=1;j<=n;j++){
			if(get[i][j-1]>get[i-1][j]){
				get[i][j]=get[i][j-1]+ame[i][j];
			}else{
				get[i][j]=get[i-1][j]+ame[i][j];
			}
		}
	}
	printf("%d",get[2][n]);
		
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

//fn tenki(s: String, t: String) -> u8 {
//    let mut ans = 0;
//    let sv :Vec<char> = s.chars().collect();
//    let tv :Vec<char> = t.chars().collect();
//    for i in 0..3 {
//        if sv[i] == tv[i] {
//            ans += 1;
//        }
//    }
//    ans
//}

fn main() {
    let a1: u8 = read();
    let a2: u8 = read();
    let a3: u8 = read();
    let ans;
    if a1 + a2 + a3 >= 22 {
        ans = "bust";
    } else {
        ans = "win";
    }
    
    println!("{}", ans);

}



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

int main() {
    int N; cin >> N;
    vector<int> L(N); for (int i = 0; i < N; i++) cin >> L[i];
    sort(L.begin(), L.end(), less<int>());
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N-1; j++) {
            int a = L[i], b = L[j];
            if (a + b > L[j+1]) {
                int ok = j+1, ng = N;
                while (ng - ok != 1) {
                    int med = (ok + ng) / 2;
                    if (a + b > L[med]) ok = med;
                    else ng = med;
                }
                ans += (ok - j);
            }
        }
    }
    cout << ans << endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

// rt(a)+rt(b) < rt(c)
// a+b+2rt(ab) < c
// c - a - b > 2rt(ab)
//(c - a - b)^2 > 4ab

inline bool check(li a, li b, li c) {
    if (c - a - b < 0) {
        return false;
    }
    li cab = c - a - b;
    return (cab * cab > 4 * a * b);
}


int main() {
    li a, b, c;
    cin >> a >> b >> c;
    cout << (check(a, b, c) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,t,seven[10],judge,j;
    int n[200];
    char en[3];
    scanf("%d", &t);
    for(i=0;i<4;i++){
	n[i] = t % 10;
	t /= 10;
    }
    seven[0] = n[3]+n[2]+n[1]+n[0];
    seven[1] = n[3]-n[2]+n[1]+n[0];
    seven[2] = n[3]+n[2]-n[1]+n[0];
    seven[3] = n[3]-n[2]-n[1]+n[0];
    seven[4] = n[3]+n[2]+n[1]-n[0];
    seven[5] = n[3]-n[2]+n[1]-n[0];
    seven[6] = n[3]+n[2]-n[1]-n[0];
    seven[7] = n[3]-n[2]-n[1]-n[0];
    for(i=0; i<8;i++){
	if(seven[i] == 7){
	    judge = i;
	    for(j=0;j<3;j++){
		en[j] = judge %2;
		judge /= 2;
		if(en[j] == 0){
		    en[j] = '+';
		}
		else{
		    en[j] = '-';
                }
	    }
	}
    }
    printf("%d%c%d%c%d%c%d=7\n", n[3],en[0],n[2],en[1],n[1],en[2],n[0]);
    return 0;
}

Measured memory_bytes: 128
//abc151E
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b) {
  return *(int*) a - *(int*) b;
}

long long gya(long long a) { //逆元を求める
  long long m=1000000007, b=m, u=1, v=0, c, t;
  while(b){
    t=a / b; //何これ
    a-=t * b, u-=t * v; //何これ
    c=a, a=b, b=c, c=u, u=v, v=c; //swap
  }
  return (u + m) % m;
}

int main(void) {
  int n, k, i;
  long long ans=0, mod=1000000007,ret=1;
  scanf(" %d %d", &n, &k);
  int a[n];

  for(i=0; i < n; i++) scanf(" %d", &a[i]);
  qsort(a, n, sizeof(int), compare_int);

  ans=a[k - 1] - a[n - k];
  for(i=1; i < n - k + 1; i++){
    ret=ret * (i + k - 1) % mod * gya(i) % mod;
    ans=(ans + (a[i + k - 1] - a[n - k - i]) * ret) % mod;
  }
  printf("%lld", ans);
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;
  int cnt = 0, pre = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == '(') { ++cnt; }
    else if (--cnt < 0) {
        cnt = 0;
        ++pre;
    }
  }
  string ans = string(pre, '(') + s + string(cnt, ')');
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const adjLists = Array.from(Array(n), () => []);
  lines.forEach((l, i) => l.split(' ').splice(2).forEach(e => adjLists[i].push(e-1)));

  const d = [], f = [];
  dfs(adjLists, d, f);
  for (let i = 0; i < n; i++) {
    console.log(i + 1, d[i], f[i]);
  }
})();

function dfs(adjLists, d, f) {
  const WHITE = 0, GRAY = 1, BLACK = 2;
  const size = adjLists.length;
  const color = Array.from(adjLists, () => WHITE);

  let time = 0;
  function visit(u) {
    color[u] = GRAY;
    d[u] = ++time;
    adjLists[u].forEach(v =>color[v] === WHITE && visit(v));
    color[u] = BLACK;
    f[u] = ++time;
  }
  adjLists.forEach((e, u) => color[u] === WHITE && visit(u));
}



Measured memory_bytes: 16812
// 177

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main(){
    int  x;
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else if(x == 1) cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;

namespace B__Touitsu
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            char[][] s = new char[3][];
            s[0] = Console.ReadLine().ToCharArray();
            s[1] = Console.ReadLine().ToCharArray();
            s[2] = Console.ReadLine().ToCharArray();

            int Count = 0;

            for(int i=0;i<N;i++)
            {
                if (s[0][i] == s[1][i])
                {
                    if (s[0][i] == s[2][i])
                        Count += 0;
                    else
                        Count += 1;
                } 
                else
                {
                    if (s[1][i] == s[2][i] || s[0][i] == s[2][i])
                        Count += 1;
                    else
                        Count += 2;
                }

            }

            Console.WriteLine(Count.ToString());
        }
    }
}


Measured memory_bytes: 11220
/*g++ main.cpp -o main.out*/
/*./main.out*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toLong() }

    // 各レベルのバーガーの層の数
    val lx = mutableListOf<Long>()
    var l = 1L
    lx.add(l)

    // 各レベルのバーガーのPの数
    var px = mutableListOf<Long>()
    var p = 1L
    px.add(p)
    
    for (i in (0..50)) {
        l = 2 * lx[i] + 3
        lx.add(l)

        p = 2 * px[i] + 1
        px.add(p)
    }

    println(count(n.toInt(), x, lx, px))
}

fun count(n: Int, x: Long, lx: List<Long>, px: List<Long>): Long {
    if (x == 0L) {
        return 0
    }
    if (n == 0) {
        return 1
    }

    var ret = 0L

    // レベルNのバーガーの総数
    var size = lx[n]
    var half = size / 2 + 1
    if (x < half) {
        // 半分より少ない時
        ret = count(n - 1, x - 1, lx, px)
    } else if (x == half) {
        // ちょうど半分の時
        ret = px[n - 1] + 1
    } else {
        // 半分より多い時
        ret = px[n - 1] + 1 + count(n - 1, x - half, lx, px)
    }

    return ret
}

Measured memory_bytes: 37568
import java.util.*;
public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String input = sc.nextLine();
      String[] inputs = input.split(" ");
      int n = Integer.parseInt(inputs[0]);
      int k = Integer.parseInt(inputs[1]);
      
      int count = 0;
      while(n != 0){
        int rem = n % k;
        n /= k;
        count++;
      }
      
      System.out.println(count);
    }
}

Measured memory_bytes: 23252
while 1:
    n = int(input())
    if n == 0:
        break
    l = input().split()
    lup, rup, up = False, False, False
    res = 0
    for s in l:
        if s == 'lu':
            lup = True
        if s == 'ru':
            rup = True
        if s == 'ld':
            lup = False
        if s == 'rd':
            rup = False
        if lup and rup:
            if not up:
                res += 1
            up = True
        if not lup and not rup:
            if up:
                res += 1
            up = False
    print(res)


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

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

	vector<int> av(n);
	for (auto& a : av) {
		cin >> a;
	}

	sort(av.begin(), av.end());

	int prev = -1;
	bool yes = true;
	for (auto& a : av) {
		if (prev == a) {
			yes = false;
			break;
		}
		prev = a;
	}

	if (yes) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
static const int MOD = 1e9 + 7;
// https://ei1333.github.io/luzhiled/
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
using modint = ModInt<MOD>;
modint solve() {
    int X, Y;
    cin >> X >> Y;
    int t1 = 2 * Y - X, t2 = 2 * X - Y;
    if (t1 % 3 || t2 % 3) return 0;
    t1 /= 3;
    t2 /= 3;
    Combination<modint> comb(t1 + t2);
    return comb.C(t1 + t2, min(t1, t2));
}
int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 8064
n = gets.split("")
ans = "Yes" 

if n.include?("N") 
  unless n.include?("S")
    ans = "No"
  end
end
if n.include?("E")
  unless n.include?("W")
    ans = "No"
  end
end
if n.include?("W")
  unless n.include?("E")
    ans = "No"
  end
end
if n.include?("S") 
  unless n.include?("N")
    ans = "No"
  end
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N;

int main(){
    cin >> N;
    vector<int> A(N+1);
    rep1(i,N) cin >> A[i];
    auto mx = max_element(A.begin()+1,A.end());
    auto mn = min_element(A.begin()+1,A.end());
    int mxi = mx - A.begin();
    int mni = mn - A.begin();
    
    cout << N + N - 1 << '\n';
    if(abs(*mx) > abs(*mn)){
        rep1(i,N) A[i] += *mx, cout << mxi << " " << i << '\n';
        rep1(i,N-1) A[i+1] += A[i], cout << i << " " << i + 1 << '\n';
    }else{
        rep1(i,N) A[i] -= *mn, cout << mni << " " << i << '\n';
        rep1(i,N-1) cout << N-i+1 << " " << N-i << '\n';        
    }
}

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)
#define pb push_back

#define test if(!true)
#define N 1007
#define MOD (ll)(1e9 + 7)

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

    vector<pr(ll, ll)> v;
    frt(i ,0, n)
    {
        ll x, y;
        cin >> x >> y;
        v.pb({y, x});
    }
    sort(all(v));
    ll i = 0;

    for(auto ele : v)
    {
        ll a = ele.second;
        ll b = ele.first;

        if(i + a > b)
        {
            cout << "No\n";
            return 0;
        }
        else
        {
            i+=a;
        }
    }
    cout << "Yes\n";
    
    return 0;
}

Measured memory_bytes: 6256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define IO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
#define pi acos(-1.00)
const int INF = 1e9 + 5;
const ll mod = 1000000007;
ll power(ll a, ll p){
    if(p == 0) return 1;
    if(p == 1) return a % mod;
    if(p & 1) return a * power(a, p - 1) % mod;
    ll r = power(a, p / 2) % mod;
    return r * r % mod;
}
void add(ll &a, ll b){
    a += b;
    if(a > mod) a -= mod;
    if(a < 0) a += mod;
}
int main() {
    IO;
    int n;
    cin >> n;
    vector<pair<ll, ll> > a(n), b(n);
    for(auto &x: a)
        cin >> x.ff >> x.ss;

    map<pair<ll, ll> , int> mp;
    set<pair<ll, ll> > s;
    for(int i = 0; i < n; i++) {
        if(a[i].ff != 0 || a[i].ss != 0) {
            ll gcd = __gcd(a[i].ff, a[i].ss);
//            cout << gcd << endl;
            a[i].ff /= gcd, a[i].ss /= gcd;
            if (a[i].ss < 0) a[i].ff *= -1, a[i].ss *= -1;
        }
        mp[{a[i].ff, a[i].ss}]++;
        s.insert({a[i].ff, a[i].ss});
    }
    ll ans = 1;

    for(auto x: s){
        if(mp[x] == -1) continue;
        if(x.ff == 0 && x.ss == 0) continue;
        if(x.ff == 0 || x.ss == 0){
            ll val = power(2, mp[{x.ff, x.ss}]);
            add(val, power(2, mp[{x.ss, x.ff}]));
            add(val, -1);
            ans *= val;
            mp[{x.ff, x.ss}] = mp[{x.ss, x.ff}] = -1;
        }
        else{
            if(x.ff < 0) {
                ll val = power(2, mp[{x.ff, x.ss}]);
                add(val, power(2, mp[{x.ss, -x.ff}]));
                add(val, -1);
                ans *= val;
                mp[{x.ff, x.ss}] = mp[{x.ss, -x.ff}] = -1;
            }
            else{
                ll val = power(2, mp[{x.ff, x.ss}]);
                add(val, power(2, mp[{-x.ss, x.ff}]));
                add(val, -1);
                ans *= val;
                mp[{x.ff, x.ss}] = mp[{-x.ss, x.ff}] = -1;
            }
        }
        ans %= mod;
    }
    add(ans, mp[{0, 0}]);
    add(ans, -1);
    cout << ans << '\n';
    return 0;
}


/*
1 2 3 4 5

 1
 2
 3
 4
 5
 1 2
 1 3
 1 4 <
 1 5
 2 3
 2 4 <
 2 5
 3 4
 3 5
 4 5
 1 2 3
 1 2 4 <
 1 2 5
 1 3 4 <
 1 3 5
 1 4 5 <
 2 3 4 <
 2 3 5
 2 4 5 <
 3 4 5
 1 2 3 4 <
 1 2 3 5
 1 2 4 5 <
 1 3 4 5 <
 2 3 4 5 <
 1 2 3 4 5 <

*/

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

int main() {
  char X,Y;
  cin>>X>>Y;
  int x,y;
  if(X=='A'){
  	x=1;
  }
  if(X=='B'){
  	x=2;
  }
  if(X=='C'){
  	x=3;
  }
  if(X=='D'){
  	x=4;
  }
  if(X=='E'){
  	x=5;
  }
  if(X=='F'){
  	x=6;
  } 
  if(Y=='A'){
   	y=1;
   }
  if(Y=='B'){
   	y=2;
   }
  if(Y=='C'){
   	y=3;
   }
  if(Y=='D'){
   	y=4;
   }
  if(Y=='E'){
   	y=5;
   }
  if(Y=='F'){
   	y=6;
   }
  if(x>=y+1){
  	cout<<'>'<<endl;
  } 
  if(x+1<=y){
  	cout<<'<'<<endl;
  }
  if(x==y){
  	cout<<'='<<endl;
  }
  
   
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N = int(sys.stdin.readline())
K = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

ans = 0
for l in L:
    ans += min(2 * l, 2 * abs(l - K))
print(ans)

Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> b(M);
  for(int i = 0; i < M; i++){
    cin >> a.at(i);
    cin >> b.at(i);
  }
  
  for(int i = 0; i < N; i++){
    int num = 0;
    
    for(int j = 0; j < M; j++){
      if(a.at(j) == i + 1){
        num++;
      }
      if(b.at(j) == i + 1){
        num++;
      }
    }
    
    cout << num << endl;
  }
  
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
S = [input() for i in range(n)]
common = set(S[0])
cnt = Counter(S[0])
for i in range(0,n):
    c = Counter(S[i])
    common = common & set(c.keys())
    for j in cnt.keys():
        if j in common and cnt[j] > c[j]:
            cnt[j] = c[j]
        elif j not in common:
            cnt[j] = 0

ans = []          
for k,v in cnt.items():
    ans.append(k*v)

ans.sort()
print(''.join(ans))

Measured memory_bytes: 3316