akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int D[6];
    for(int i = 0; i < 6; i++){
        D[i] = 0;
    }
    for(int i = 0; i < 6; i++){
        cin >> D[i];
    }
    int U = D[0];
    int S = D[1];
    int E = D[2];
    int W = D[3];
    int N = D[4];
    int L = D[5];
    char call;
    while((call = getchar()) != EOF){
        if(call == 'E'){
            int temp = L;
            L = E;
            E = U;            
            U = W;
            W = temp;
        }
        if(call == 'W'){
            int temp = L;
            L = W;
            W = U;
            U = E;
            E = temp;
        }
        if(call == 'N'){
            int temp = L;
            L = N;
            N = U;
            U = S;
            S = temp;
        }
        if(call == 'S'){
            int temp = L;
            L = S;
            S = U;
            U = N;
            N = temp;
        }
    }
    cout << U << endl;
    return 0;
}



Measured memory_bytes: 3120
a,b,c,d=map(int,input().split())

if b<0 and d<0:
    print(a*c)
elif a>=0 and c>=0:
    print(b*d)
elif b<0 and c>=0:
    print(b*c)
elif a>=0 and d<0:
    print(a*d)
else:
    if a*c>=b*d:
        print(a*c)
    else:
        print(b*d)


Measured memory_bytes: 9184
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    int count = 0;
    for (int i = 1; i <= N; i++) {
        if (i >= 1 && i < 10) {
            count++;
        } else if (i >= 100 && i < 1000) {
            count++;
        } else if (i >= 10000 && i < 100000) {
            count++;
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class PaizaSample
{


    static void Main()
    {
        while (true)
        {

            int[] input = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

            int n = input[0];
            int m = input[1];
            if (n == 0 && m == 0)
            {
                break;
            }

            List<int> list = new List<int>();
            for (int i = 1; i <= n; i++)
            {
                list.Add(i);
            }

            int cursol = m-1;
            while (true)
            {
                if (list.Count == 1)
                {
                    break;
                }

                //Console.WriteLine(list[cursol]);
                list.RemoveAt(cursol);

                if (cursol + m - 1 >= list.Count)
                {
                    cursol = (cursol + m - 1) % list.Count;
                }
                else
                {
                    cursol += m - 1;
                }

            }

            Console.WriteLine(list[0]);

        }

        //Console.ReadKey();

    }
}

Measured memory_bytes: 9496
N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for i in range(N*50+1)] for j in range(N+1)] for k in range(N+1)]
for i in range(N+1):
    dp[i][0][0] = 1
for i in range(1,N+1):
    x = X[i-1]
    for j in range(1,N+1):
        for k in range(N*50+1):
            if k < x:
                dp[i][j][k] = dp[i-1][j][k]
                
            elif j > i:
                dp[i][j][k] = 0
                
            else: 
                dp[i][j][k] += dp[i-1][j][k] + dp[i-1][j-1][k-x]
ans = 0
for i in range(1,N+1):
    ans += dp[N][i][A*i]
print(ans)


Measured memory_bytes: 96732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main(){
	int h, a;
	cin>>h>>a;
	cout<<ceil(double(h)/a);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  rep(i, n) cin >> S[i];

  string s = S[0];
  for(int i = 1; i < n; i++) {
    string ns = S[i];
    if(*(--s.end()) != *ns.begin()) {
      cout << "No" << endl;
      return 0;
    }
    s = ns;
  }

  unordered_map<string, int> mp;
  rep(i, n) { mp[S[i]]++; }
  for(auto x : mp) {
    if(x.second > 1) {
      cout << "No" << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
auto const INF = (ll)1e9+7;
int main(){
    ll n;
    cin >> n;
    ll ans = 1;
    for(int i=1;i<=n;i++){
        ans=ans*i%INF;
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	int a[50];
	double val = 0.0;

	cin >> n;

	for (int  i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	sort(a, a + n);

	val = a[0];

	for (int i = 1; i < n; i++)
	{
		val = (val+ a[i]) / (double)2;
	}

	cout << val << endl;

	return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
// df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int ,int>> arr;
  rep(i, n) {
    string s;
    int p;
    cin >> s >> p;
    tuple<string, int, int> tup = make_tuple(s, -p, i + 1);
    arr.push_back(tup);
  }
  sort(arr.begin(), arr.end());
  for (auto & tup : arr) {
    int i;
    tie(ignore, ignore, i) = tup;
    cout << i << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(){
  int i;
  bool f[31];

  rep(i,31) if(i != 0) f[i] = false;
  rep(i,28){
    int num;
    scanf("%d",&num);
    f[num] = true;
  }

  rep(i,31) if(i != 0 && !f[i]) cout << i << endl;

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static int n, ans;
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		n = sc.nextInt();
		
		return true;
	}
	
	public static void solve(){
		
		ans = 1;
		for(int i = 0; i <= n; i++){
			ans += i;
		}
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 12000
#include<stdio.h>

int main()
{

	int W,H,x,y,r;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if( 0 <= y-r && y + r <=H && 0 <= x-r && x + r <= W){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;

}

Measured memory_bytes: 584
N, K = map(int, input().split())
H = list(map(int, input().split()))  # リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
s=0
if K>=N:
    print(0)
else:
    H.sort()
    for i in range(K):
        H[N-i-1]=0
    for i in range(N):
        s+=H[i]
    print(s)


Measured memory_bytes: 26024
import numpy as np
H,W = map(int,input().split())
N = int(input())
lsa = list(map(int,input().split()))
ls2 = []
for i in range(N):
    ls2 += [i+1]*lsa[i]
arr = np.array(ls2)
arr = arr.reshape(H,W).tolist()
arr2 = []
for i in range(H):
    if i % 2 == 0:
        arr2.append(arr[i])
    else:
        arr[i].reverse()
        arr2.append(arr[i])
for i in range(H):
    arr2[i] = [str(j) for j in arr2[i]]
    print(' '.join(arr2[i]))

Measured memory_bytes: 28112
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pub push_back
#define pob pop_back
#define M 1000000007
#define pii pair<ll,ll>
#define mp make_pair
using namespace std;
vector<pii >ans;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,k,j;
    cin>>n;
    if(n%2==0)
    {
        i=1;k=n;
    }
    else {i=1;k=n-1;}
    for(i=1;i<=n;i++,k--)
    {
        for(j=i+1;j<=n;j++)
        {
            if(j!=k){ans.pub(mp(i,j));}
        }
    }
    cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)cout<<ans[i].F<<" "<<ans[i].S<<endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.lang.Math;

public class Main{
	public int n;
	public int k;
	public int min;

	public void search(int i, int sum, boolean mode) {
		if(mode) {
			sum *= 2;
		} else {
			sum += k;
		}

		if(i == n) {
			// System.out.println("i : " + i + " sum : " + sum);
			min = Math.min(min, sum);
			return;
		}

		search(i + 1, sum, true);
		search(i + 1, sum, false);

		return;
	}

	public void run() {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		k = sc.nextInt();

		min = Integer.MAX_VALUE / 2;
		search(1, 1, true);

		System.out.println(min);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
#define mod 1000000007

using namespace std;
typedef long long ll;
const int N = 1e5 + 2;

void add(ll &x, ll y){
    x += y;
    while(x >= mod) x -= mod;
}

string s;
ll f[N][4];

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

    cin >> s;
    s = " " + s;
    f[0][0] = 1;
    for(int i = 1; i < (int)s.size(); i++){
        f0(j, 4){
            f[i][j] = f[i - 1][j];
            if(s[i]=='?') f[i][j] = f[i - 1][j]*3;

            add(f[i][j], 0);
            if(j > 0){
                if(s[i]=='?' || j - 1 == s[i] - 'A') add(f[i][j], f[i - 1][j - 1]);
            }
        }
    }
    cout << f[s.size() - 1][3];
}


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

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

  int a[110];
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  for(int i = 1;i <= 110;i++){
    int work = 0;
    for(int j = 0;j < n;j++){
      work += a[j];
      work -= i;
      if(work < 0){
        cout << i-1 << endl;
        return 0;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;


vecl res(1000001);

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int N;
    cin >> N;
    vecl A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    REP(i,N) res[A[i]]++;
    int ans = 0;
    REP(i,N) {
        res[A[i]]--;
        vecl e = enum_divisors(A[i]);
        bool ok = true;
        for(auto p : e) {
            if(res[p] > 0) ok = false;
        }
        if(ok) ans++;
        res[A[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12768
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-9;

int main(){
	int n;
	scanf("%d",&n);
		for(int i=0;i<n;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			if(src <= 5 && dst <= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}
			else if(src >= 5 && dst >= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					if(dst == 5){
						cout << 5 << endl;
						continue;
					}
					for(int j=5;j>=0;j--){
						printf("%d ",j);
					}

					for(int j=1;j<=4;j++){
						printf("%d ",j);
					}

					for(int j=5;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

			else{
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					for(int j=5;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

		}
}

Measured memory_bytes: 3216
h,w = map(int,input().split())
l = [list(map(int,input().split())) for i in range(h)]
count = 0
ans =[]
for i in range(h):
    for j in range(w-1):
        if l[i][j] %2 == 1:
            l[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])
            count += 1
for i in range(h-1):
    if l[i][w-1] %2 == 1:
        count += 1
        l[i+1][w-1] += 1
        ans.append([i+1,w,i+2,w])
print(count)
for i in ans:
    print(*i)

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

int main()
{
    int N, A;
    int a[4];
    cin >> N;
    A = 1;

    for (int i = 0; i < 4; i++)
    {
        int b = A;
        A *= 10;
        a[i] = N % A / b;
        N = N - a[i] * b;
    }

    if (a[0] == a[1] && a[1] == a[2])
    {
        cout << "Yes" << endl;
    }
    else if (a[2] == a[3] && a[1] == a[2])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
if n == 0
  p 0; exit
end
x = 1
ans = ""
while n.abs > 0 do
  if n.abs%2 == 1
    ans += "1"
    n -= x
  else
    ans += "0"
  end
  break if n == 0
  n = n.abs/2 * (n/n.abs)
  x = -x
end
puts ans.reverse

Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }
    ll money = 1000, kabu = 0;

    ll tugiuru = true;
    for(ll i = 0; i < n; i++){
        if(i == n-1){
            //売る
            money += kabu * vec[i];
            kabu = 0;
            continue;
        }

        if(tugiuru == true){
            //売る
            money += kabu * vec[i];
            kabu = 0;
        }

        if(vec[i] < vec[i+1]){
            //買う
            kabu = money / vec[i];
            money = money % vec[i];
            tugiuru = true;
        }

        if(vec[i] > vec[i+1]){
            continue;
        }

    }

    cout << money << endl;

}

Measured memory_bytes: 3624
s = list(input())
k = int(input())
n = len(s)
do = 0
while do<=n-1:
    rest = (97-ord(s[do]))%26
    if rest<=k:
        k -= rest
        s[do] = 'a'
        do+=1
    else:
        do+=1


if k>0:
    s[-1] = chr(ord(s[-1]) + k%26)

print(''.join(s))

Measured memory_bytes: 4152
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>


#ifdef MY_LOCAL
namespace sandbox {
#endif

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	vector<vector<int>> passages(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		passages[a].emplace_back(b);
		passages[b].emplace_back(a);
	}

	vector<int> signposts(n, -2);
	queue<int> q;
	signposts[0] = -1;
	q.push(0);
	while (!q.empty())
	{
		int this_room = q.front();
		q.pop();
		for (auto next_room : passages[this_room])
		{
			if (signposts[next_room] == -2)
			{
				q.push(next_room);
				signposts[next_room] = this_room;
			}
		}
	}

	for (auto this_signpost : signposts)
	{
		if (this_signpost == -2)
		{
			cout << "No" << "\n";
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int j = 1; j < n; j++)
	{
		cout << signposts[j] + 1 << "\n";
	}

	return 0;
}

#ifdef MY_LOCAL
}
#endif

Measured memory_bytes: 10124
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<int> b;
    
    for (int i = 0; i < n; i++) {
        bool ng = true;;
        for (int j = (int)a.size() - 1; j >= 0; --j) {
            if (a[j] == j + 1) {
                b.push_back(j + 1);
                a.erase(a.begin() + j);
                
                ng = false;
                break;
            }
        }
        
        if (ng) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    for (int i = n - 1; i >= 0; --i) {
        cout << b[i] << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var X = new List<X>();
            foreach (var input in ReadLongs().Select((x, i) => new { Index = i, Value = x }))
            {
                X.Add(new X
                {
                    Index = input.Index,
                    Value = input.Value,
                });
            }

            X = X.OrderBy(x => x.Value).ToList();

            for (int i = 0; i < N; i++)
            {
                if (i <= N / 2 - 1)
                {
                    X[i].Result = X[(int)N / 2].Value;
                }
                else
                {
                    X[i].Result = X[(int)N / 2 - 1].Value;
                }
            }
            var sb = new StringBuilder();
            foreach (var x in X.OrderBy(a => a.Index))
            {
                sb.AppendLine(x.Result.ToString());
            }

            return sb.ToString().Trim();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
    class X
    {
        public int Index { get; set; }
        public long Value { get; set; }
        public long Result { get; set; }
    }
}


Measured memory_bytes: 72700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define ll long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

vector<string> v;

signed main(){
	
	string s;cin >> s;
	int ans = 0;
	int cnt = 0;
	rep(i,s.size())
	{
		if(s[i] == 'T') cnt++;
		else cnt--;
		ans = max(ans,cnt);
	}
	
	
	cout << ans * 2 << endl;
	
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n, q;
	cin >> n >> q;
	ll ans[n];
	REP(i, n) ans[i] =0;
	vector<int> G[n], RT[n];
	REP(i, n-1){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	int p[n];
	REP(i, n) p[i] = -1;
	p[0] = 0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int f = que.front(); que.pop();
		for(int v: G[f]){
			if(p[v] == -1){
					p[v] = f;
					RT[f].pb(v);
					que.push(v);
			}
		}
	}
	REP(i, q){
		int v, x;
		cin >> v >> x;
		v--;
		ans[v] += x;
	}
	que.push(0);
	while(!que.empty()){
		int f = que.front(); que.pop();
		for(int rn: RT[f]){
			ans[rn] += ans[f];
			que.push(rn);
		}
	}
	REP(i, n){
		cout << ans[i];
		if(i == n-1) cout << endl;
		else cout << " ";
	}
	return 0;
} 


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

int euku(int,int);

int main(){
  int i;
  long long n,m;
  long long p;
  long long q;
  int l=0;

  scanf("%lld %lld",&n,&m);

  unsigned char s[1000000];
  unsigned char t[1000000];

  scanf("%s",s);
  scanf("%s",t);

  if(s[0]!=t[0]){
    l++;
  }
  q = euku(n,m);
  p = n*m/euku(n,m);

    for(i=0; i<=q; i++){
      if(s[i*n/q]!=t[i*m/q]){
        l++;
      }
    }

  if(l==0){
    printf("%lld\n",p);
  }else if(l>0){
    printf("-1\n");
  }

  return 0;
}

int euku(int a,int b){
  int r;
  if(a>=b){
    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    return b;
  }else{
    r = b % a;
    while(r!=0){
      b = a;
      a = r;
      r = b % a;
    }
    return a;
  }
}



Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// -----------------------------------------------------------------------------
// main
// -----------------------------------------------------------------------------
fn main(){
    input!{
        n: i32
    }
    let mut ans = vec![];
    for i in 1..n+1{
        // 奇数のみ
        if i%2==1{
            let mut d = vec![];
            for j in 1..i+1{
                if i%j==0{
                    d.push(j);
                }
            }
            if d.len()==8{
                ans.push(i);
            }
        }
    }
    println!("{}", ans.len());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("03")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const int maxn = 1;
const int maxe = 20;
int n,m,a[maxn],c=0,k,pa[maxn];
double f=0;
int st[maxn][maxe];

void build(int n){
    for(int j=1;(1<<j)<=n;j++){
        for(int i=1;i+(1<<j)-1<=n;i++){
            st[i][j] = min(st[i][j-1], st[i+(1<<(j-1))][j-1]);
        }
    }
}

int query(int a, int b){
    int k = 31- __builtin_clz(b-a+1);
    return min(st[a][k], st[b-(1<<k)+1][k]);
}

int find(int i)
{
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}

int bs(int l,int r,int x)
{
    while(l!=r)
    {
        int mi=(l+r)/2;
        if(a[mi]>x)r=mi;
        else l=mi+1;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);

    cin>>n;
    if(n==1)cout<<"1.0000000000";
    else if(n%2==0)cout<<"0.5000000000";
    else {
    k=n/2;
    f=k+1;
    f/=n;
    cout<<f;
}
}


Measured memory_bytes: 256
n = int(input())
works = []
for _ in range(n):
    a,b = map(int,input().split())
    works.append([a,b])
works = sorted(works,key=lambda x:x[1])
time = 0
flag = 0
for work in works:
    a,b = work
    time += a
    if time > b:
        flag = 1
        break

if flag == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 39700
#include <iostream>
#define ll long long
using namespace std;
int main() {
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    ll arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    ll dp[n+1];
    for(int i=0;i<=n;i++){
        dp[i]=0;
    }
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=2;j<=k;j++){
            if(i>j){
            dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }

        }
       
    }
    cout<<dp[n];

}


Measured memory_bytes: 1792
A,B=map(int,input().split())
def f(X):
  if X%4==0:
    return X
  elif X%4==1:
    return 1
  elif X%4==2:
    return 1^X
  elif X%4==3:
    return 0
if A==0:
  ans=f(B)
else:
  ans=f(A-1)^f(B)
print(ans)

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


using namespace std;
double pi=3.14159265358979323846264338;
bool cust[1000001];
vector<int> cust2[1000001];
bool ok[1000001];
bool ok2;
int gcd(int a,int b){
	if(b==0)return a;
	a=a%b;
	return gcd(b,a);
}
int main(){
	int n,m;
	for(int i=2;i<=1000000;i++){
		if(cust[i])continue;
		cust[i]=true;
		for(int j=i;j<=1000000;j+=i){
			cust[j]=true;
			cust2[j].push_back(i);
		}
	}
	cin>>n;
	int a;
	cin>>a;
	int g=a;
	for(auto b:cust2[a])ok[b]=true;
	for(int i=1;i<n;i++){
		cin>>a;
		g=gcd(max(g,a),min(g,a));
		if(ok2)continue;
		for(auto c:cust2[a]){
			if(ok[c]){ok2=true;break;}
			ok[c]=true;
		}
	}
	if(!ok2)cout<<"pairwise coprime"<<endl;
	else if(g==1)cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
	return 0;
}

Measured memory_bytes: 60968
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const double pi=3.1415926536;
#define fo(i,n) for( ll int i=0;i<n;++i)
#define fos(j,i,n) for(ll int j=i;j<n;++j)
#define nax 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define abs(x) ((x)<0?(-(x)):(x))
#define dis(k) cout << k << endl
#define forr(i,n) for( ll int i= n-1;i>=0;--i)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ve vector
#define fi first
#define se second
#define setzero(a) memset(a,0,sizeof(a))
#define setinf(a) memset(a,0x7F,sizeof(a))
typedef ve< ll > vi;
typedef ve< vi > vvi;
typedef pair< ll ,ll > ii;


//weird debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
		sim > struct rge { c b, e; };
		sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
		sim > auto dud(c* x) -> decltype(cerr << *x, 0);
		sim > char dud(...);
		struct debug {
#ifdef LOCAL
			~debug() { cerr << endl; }
			eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


/*Don't just sit and hope that God will solve this
  fucking do something, try to observe or solve it a different way.
  Use that pen and paper.
  If nothing works take a deep breath and start again.*/

void solve(){
	ll n;
	cin >> n;
	long double a[n];
	fo(i,n) cin >> a[i];
	ve<ve<long double>> dp(n,ve<long double>(n+2,0.0));
	dp[0][1]=1.0-a[0];
	dp[0][2]=a[0];
	fos(i,1,n){
		fos(j,1,n+2){
			dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1.0-a[i]);
		}
	}
	long double ans=0.0;
	fos(i,n/2+2,n+2) ans+=dp[n-1][i];
	cout << setprecision(10) << ans << endl;

}

int main(){
	fast;
	int t=1;
	int tt=1;
	//cin >> t;

	while(t--){
		//cout << "Case #" << tt << ": " ;
		tt++;
		solve();
	}
	return 0;
}



Measured memory_bytes: 144220
#include<stdio.h>
int main() {
	int n, x, i, j, k, a;
	while (1) {
		a = 0;
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) {
			break;
		}
		for (i = 1;i <= n-2;i++) {
			for (j = i + 1;j <= n-1;j++) {
				for (k = j + 1;k <= n;k++) {
					if (i + j + k == x) {
						a=a+1;
					}
				}
			}
		}
		printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 600
n,m=gets.chomp.split(" ").map(&:to_i)

a_array=gets.chomp.split(" ").map(&:to_f).sort {|a, b| b <=> a }
if n == 1
    puts (a_array[0] / (2 ** m)).to_i
    exit
end

queue = Hash.new{|hash, key| hash[key] = []}
key = 1
a_array.each do |e|
    while true
        if a_array[0] / (2 ** key) <= e
            break
        else
            key += 1
        end
    end
    queue[key].push(e)
end

def merge_sort(left, right)
    return left if right.empty?
    return right if left.empty?
    len = left.length + right.length
    lv = left.shift
    rv = right.shift
    len.times.map{
        if lv > rv
            lv.tap{ lv = left.empty? ? (right.empty? ? rv : right.last) : left.shift }
        else
            rv.tap{ rv = right.empty? ? (left.empty? ? lv : left.last) : right.shift }
        end
    }
end
  
target = 1
while m > 0 do
    if m <= queue[target].length
        (0..(m-1)).each do |i|
            queue[target][i] = queue[target][i] / 2
        end
        break
    else
        divided = queue[target].map {|e| e / 2 }
        m = m - divided.length
        queue[target+1] = merge_sort(queue[target+1], divided)
        queue.delete(target)
    end
    target += 1
end

puts queue.values.flatten.map(&:to_i).inject(&:+)



Measured memory_bytes: 13696
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}


int main(){

    int X, Y; cin >> X >> Y;

    combination c(1000005);

    if ((X+Y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int move_count = (X+Y)/3;
    int x = X-move_count;
    int y = Y-move_count;

    mint ans = c(x+y, x);

    cout << ans << endl;;

}

Measured memory_bytes: 18800
N = int(input())
li = [ [ int(it) for it in input().split() ]  for i in range(N) ]
iru = [[1]*N for i in range(N)] 

Flag = True
s = 0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if ( i==j or j==k or k==i ):
        continue
      if ( li[i][j] > li[i][k] + li[k][j] ):
        Flag = False
      if ( li[i][j] == li[i][k] + li[k][j] ):
        iru[i][j]=0
for i in range(N):
  for j in range(N):
    if (i<j):
      s += iru[i][j] * li[i][j]

print ( s if Flag else -1 )

Measured memory_bytes: 46172
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

llong a,b;
llong n;

llong f(llong i){
	return a*i/b-a*(i/b);
}

int main(){
	cin>>a>>b>>n;
	
	if(n<b){
		cout<<f(n)<<endl;
		return 0;
	}
	
	cout<<f(b-1)<<endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int K = sc.nextInt();
    int C = Math.min(A,B);
    int count = 0;
    
    for(int i=1;i<=C;i++){
      if(A%i==0 && B%i==0){
        count++;
      }
    }
    int[] line = new int[count];
    int cc = 0;
    for(int j=1;j<=C;j++){
      if(A%j==0 && B%j==0){
        line[cc] = j;
        cc++;
      }
    }
   System.out.println(line[line.length-K]);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
int main(void){
    long N,K,M;
    cin >> N >> K;
    
    double p=0;
    if(N>K)M=K-1;
    else M=N;
    for(long i=1;i<=N;i++){
        if(i<K){
            int x=0;
            for(int j=i;j<K;j=j*2){
                x++;
            }
            p += (double)1.0/N * (double)pow(0.5,(double)x);
        }else{
            p += (double)1.0/N;
        }
        
    }
    
    cout << std::setprecision(12) << p << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 100005
using namespace std;
void solve(){
    float d,t,s;
    cin>>d>>t>>s;
    float tm=d/s;
    if(tm<=t) cout<<"Yes";
    else cout<<"No";
}
int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3712
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
    that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
    for (int j=0; j<=n; j++) 
    { 
    if (i == 0 || j == 0) 
        L[i][j] = 0; 
    else if (X[i-1] == Y[j-1]) 
        L[i][j] = L[i-1][j-1] + 1; 
    else
        L[i][j] = max(L[i-1][j], L[i][j-1]); 
    } 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0' ; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
    // If current character in X[] and Y are same, then 
    // current character is part of LCS 
    if (X[i-1] == Y[j-1]) 
    { 
        lcs[index-1] = X[i-1]; // Put current character in result 
        i--; j--; index--;   // reduce values of i, j and index 
    } 

    // If not same, then find the larger of two and 
    // go in the direction of larger value 
    else if (L[i-1][j] > L[i][j-1]) 
        i--; 
    else
        j--; 
} 

// Print the lcs 
cout <<lcs<<endl; 
} 

/* Driver program to test above function */
int main() 
{ 
    /*#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  #endif*/
char X[3005]; 
char Y[3005];
scanf("%s %s", X, Y); 
int m = strlen(X); 
int n = strlen(Y);
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename V> typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }

typedef pair<int, int> P;
vector<vector<P> > V;
int N, Q;
string S;


bool lcheck(int mid) {
	if (mid == -1)return true;
	int cur = mid;
	int time = -1;
	while (cur != -1) {
		int dist = distance(V[S[cur]-'A'].begin(),upper_bound(ALL(V[S[cur] - 'A']), P(time, 2)));
		if (dist >= SZ(V[S[cur]-'A']))return false;
		time = V[S[cur] - 'A'][dist].first;
		cur += V[S[cur] - 'A'][dist].second;
		if (cur == -1)return true;
		if (cur == N)return false;
	}
	return false;
}
bool rcheck(int mid) {
	if (mid == N)return true;
	int cur = mid;
	int time = -1;
	while (cur != N) {
		int dist = distance(V[S[cur]-'A'].begin(), upper_bound(ALL(V[S[cur] - 'A']), P(time, 2)));
		if (dist >= SZ(V[S[cur] - 'A']))return false;
		time = V[S[cur] - 'A'][dist].first;
		cur += V[S[cur] - 'A'][dist].second;
		if (cur == -1)return false;
		if (cur == N)return true;
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> Q;
	cin >> S;
	V = make_v<P>(26, 0);
	REP(i, Q) {
		char t, d;
		cin >> t >> d;
		V[t - 'A'].push_back(P(i, d == 'L' ? -1 : 1));
	}
	int ok = -1;
	int ng = N;
	lcheck(4);
	rcheck(6);
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		if (lcheck(mid))ok = mid;
		else ng = mid;
	}
	int ans = ok + 1;
	ok = N;
	ng = -1;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		if (rcheck(mid))ok = mid;
		else ng = mid;
	}
	ans += N - ok;
	cout << N - ans << endl;
	return 0;
}


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

const int maxn=1e5+5;

int N;
int H[maxn];

int main()
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",H+i);
    }
    H[0]=max(H[0]-1,1);
    string res="Yes";
    for(int i=1;i<N;i++)
    {
        if(H[i]<H[i-1])
        {
            res="No";
            break;
        }
        H[i]=max(H[i]-1,H[i-1]);
    }
    cout<<res<<endl;
    return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;


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

    int l = (int)s.size();
    int cnt = 0;
    for(int i=0; i<=l-3; ++i){
        string t = s.substr(i,3);
        if(t=="ABC") ++cnt;
    }
    cout(cnt);
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<ll> a(n+1);
	rep(i, n) cin >> a[i];
	ll yen = 1000;
	ll kabu = 0;
	rep(i, n) {
		if(i>0) if (a[i] > a[i-1]) {
			yen += kabu * a[i];
			kabu = 0;
		}
		if (a[i+1] > a[i]) {
			kabu += yen / a[i];
			yen -= kabu * a[i];
		}
		// cout << yen << endl;
	}
	cout << yen << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    int a;
    for (int i = 0; i < N; i++){
        cin >> a;
        while(a % 2 == 0){
            cnt++;
            a /= 2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val bits = BIT(n)

    aa.forEachIndexed { idx, a ->
        bits.add(idx, a)
    }

    repeat(q) {
        val (t, u, v) = readLine()!!.split(" ").map { it.toLong() }
        if (t == 0L) {
            bits.add(u.toInt(), v)
        } else {
            println(bits.sum(u.toInt(), v.toInt()))
        }
    }
}

private class BIT(val size: Int) {
    private val data = LongArray(this.size){0L}

    fun add(idx: Int, value: Long) {
        var i = idx+1
        while (i <= this.size) {
            this.data[i-1] += value
            i += i and -i
        }
    }

    // NOTE: data[rIdx] is not included
    fun sum(rIdx: Int): Long {
        var i = rIdx
        var sum = 0L

        while (i > 0) {
            sum += this.data[i-1]
            i -= i and -i
        }

        return sum
    }

    // NOTE: data[rIdx] is not included
    fun sum(lIdx: Int, rIdx: Int): Long {
        return sum(rIdx)-sum(lIdx)
    }
}


Measured memory_bytes: 126520
import java.util.Scanner;
 
//Time Card
public class Main{
 
    void run(){
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<3;i++){
            int h = sc.nextInt();
            int m = sc.nextInt();
            int s = sc.nextInt();
            int e = h*3600+m*60+s;
            h = sc.nextInt();
            m = sc.nextInt();
            s = sc.nextInt();
            int t = h*3600+m*60+s-e;
            System.out.println(t/3600+" "+t%3600/60+" "+t%60);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 26088
def ge_div(a, b):
    while a!=0:
        yield a/b,a%b
        a = (a%b)*10

while True:
    try:
        p, q = map(int, raw_input().split())
    except:
        break
    rem_list = [p]
    ans = ""
    index = -1
    for a,b in ge_div(10*p,q):
        ans += str(a)
        if b in rem_list:
            index = rem_list.index(b)
            break
        rem_list.append(b)
    print ans
    if not index == -1:
        print " "*index + "^"*(len(ans)-index)

Measured memory_bytes: 4236
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n,k;
  cin>>n>>k;
  int ans=0;
  rep(i,n){
    int x;
    cin>>x;
    ans+=min(x*2,abs(k-x)*2);
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 256