akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007

string arr[1000001];
long long r, c, dp[1004][1004];

bool valid(int x, int y){
    return (x<r && y<c && arr[x][y]=='.');
}

long long solve(int x, int y){
    if(x==r-1 && y==c-1) return 1;

    long long &ret = dp[x][y];
    if(~ret) return ret;

    ret = 0;
    if(valid(x, y+1)) ret = (ret%MOD + solve(x, y+1)%MOD)%MOD;
    if(valid(x+1, y)) ret = (ret%MOD + solve(x+1, y)%MOD)%MOD;

    return ret;
}

int main(){

    cin >> r >> c;
    for(int i=0; i<r; i++) cin >> arr[i];

    memset(dp, -1, sizeof dp);

    cout << solve(0, 0);
}


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

int main() {
  string s, t;
  cin >> s >> t;

  int ans = 0;
  rep(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

/*
*/


Measured memory_bytes: 3928
#include <stdio.h>
#define MEM 100000

int main(void) {
    int N, M, broken[MEM], b = 0;
    long stairs[MEM];

    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) scanf("%d", broken+i);

    if (0 != (broken[b]-1)) {
        stairs[0] = 1;
    } else {
        stairs[0] = 0;
        b++;
    }
    if (1 != (broken[b]-1)) {
        stairs[1] = 1 + stairs[0];
    } else {
        stairs[1] = 0;
        b++;
    }

    for (int i = 2; i < N; i++) {
        if (i != broken[b]-1) {
            stairs[i] = stairs[i-1] + stairs[i-2];
            if(stairs[i] >= 1000000007) stairs[i] %= 1000000007;
        } else {
            stairs[i] = 0;
            b++;
        }
    }

    printf("%d\n", stairs[N-1]);
    return 0;
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
	ll N;
	vector<ll> A;
	cin >> N;
	rep(i, 0, N){
		ll tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	ll cnt = 0;
	while (true){
		ll tmpCnt = 0;
		rep(i, 0, N){
			if (0 != A[i] % 2){
				break;
			}
			A[i] /= 2;
			tmpCnt++;
		}
		if (N != tmpCnt){
			break;
		}
		cnt++;
	}
	cout << cnt << endl;
 	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N-1];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for (int i = 0; i < N-1; i++) {
			C[i] = sc.nextInt();
		}
		int ans = B[0];
		for (int i = 1; i < N; i++) {
			ans += B[i];
			if (A[i-1] == A[i] - 1) {
				ans += C[A[i]-2];
			}
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 22356
#include<iostream>

using namespace std;

int main(){
    int n, a[100001],b[100001];
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++){
        b[a[i]] = i;
    }
    for(int i = 1; i <= n; i++) cout << b[i] << " ";
    cout << endl;
    return 0;
}

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

int main(){
	int N, T;
	cin >> N >> T;
	const int _N = N;
	int c[_N],t[_N];
	for(int i=0;i<_N;i++){
		cin >> c[i] >> t[i];
	}
/*
	for(int i=0;i<_N;i++){
		cout << c[i] << t[i];
	}*/
	int C = 1001;
	for(int i=0;i<_N;i++){
		if(t[i] <= T){
			if(c[i] < C){
				C = c[i];
			}
		}
	}
	if(C != 1001){
		cout << C;
	}else{
		cout << "TLE";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

template <class T, class U>
T lexical_cast(const U & from) {
    stringstream ss;
    ss << from;
    T to;
    ss >> to;
    return to;
}

string to_str(int num, int len) {
    char buf[80];
    sprintf(buf, "%0*d", len, num);
    return string(buf);
}

string AS, BS;

int bfs(int index, int restk, int borrow, string revC) {
    if(index == AS.length()) {
        reverse(revC.begin(), revC.end());
        return lexical_cast<int>(revC);
    }

    if(AS[index] - borrow >= BS[index]) {
        revC += AS[index] - borrow - BS[index] + '0';
        // cerr << index << ',' << restk << ',' << borrow << "-> case1 " << revC << endl;
        return bfs(index + 1, restk, 0, revC);
    }
    else {
        revC += AS[index] - borrow + 10 - BS[index] + '0';
        // cerr << index << ',' << restk << ',' << borrow << "-> case2 " << revC << endl;
        int res = bfs(index + 1, restk, 1, revC);
        if(restk > 0) res = max(res, bfs(index + 1, restk - 1, 0, revC));
        return res;
    }
}

int main() {
    int A, B, K; cin >> A >> B >> K;
    const int len = lexical_cast<string>(A).length();
    AS = to_str(A, len);
    BS = to_str(B, len);
    reverse(AS.begin(), AS.end());
    reverse(BS.begin(), BS.end());
    int num = bfs(0, K, 0, "");
    cout << num << endl;
}

Measured memory_bytes: 1284
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define N 200010
ll d[N];
int main(){
  ll n; string s;
  cin>>n>>s;
  char bef='W';
  for(int i=0;i<2*n;i++){
      d[i]=(bef!=s[i]);
      bef=s[i];
  }
  d[2*n]=(bef!='W');
  ll ans=1,cnt=0;
  ll lcnt=0,rcnt=0;
  for(int i=0;i<2*n;i++){
      //cout<<d[i]<<endl;
      if(d[i]==0){
	  if(cnt<=0){
	      cout<<0<<endl;
	      return 0;
	  }
	  ans=ans*cnt%mod;
	  cnt--;
	  d[i+1]^=1;
	  lcnt++;
      }
      else cnt++,rcnt++;
  }
  if(lcnt!=rcnt)cout<<0<<endl;
  else if(d[2*n]==1)cout<<0<<endl;
  else{
      ans%=mod;
      for(ll i=1;i<=n;i++)ans=ans*i%mod;
      cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> stairs(m);
  for(int i = 0; i < m; ++i) cin >> stairs[i];
  vector<int> dp(n + 1);
  dp[0] = 1;
  dp[1] = 1;
  for(int i = 0; i < m; ++i){
    dp[stairs[i]] = -1;
  }
  for(int i = 2; i < n + 1; ++i){
    if(dp[i] == -1) continue;
    if(dp[i - 1] != -1 && dp[i - 2] != -1) dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    else {
      if(dp[i - 1] == -1) dp[i] = dp[i - 2];
      else dp[i] = dp[i - 1];
    }
  }
  if(dp[n] == -1) cout << 0 << endl;
  else cout << dp[n] << endl;
}

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

int n,m;
vector<int> a;

void luan(){
	cin>>n>>m;
	for (int i=1,u;i<=m;i++){
		cin>>u;
		a.push_back(u);
	}
	if (n>=m){
		cout<<"0\n";
		return;
	}
	sort(a.begin(),a.end());
	for (int i=1;i<m;i++){
		a[i-1]=a[i]-a[i-1];
	}
	a.pop_back();
	sort(a.begin(),a.end());
	int c=m-n;
	int ans=0;
	while (c--){
		ans+=a[c];
	}
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	luan();
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int Nmax = 500;
int N;
int X[Nmax];

bool Xcmp(int i, int j){
    return X[i] < X[j];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> X[i];
        X[i]--;
    }

    vector<int> xi;
    for(int i=0; i<N; i++) xi.push_back(i);
    sort(xi.begin(), xi.end(), Xcmp);

    int last=0;
    vector<int> ans(N*N, -1);
    queue<int> free;
    for(int i=0; i<N; i++){
        if(ans[X[xi[i]]] > 0){
            cout << "No" << endl;
            return 0;
        }
        ans[X[xi[i]]] = xi[i]+1;
        for(int j=0; j<xi[i]; j++){
            if(last+j >= X[xi[i]]){
                cout << "No" << endl;
                return 0;
            }
            while(ans[last+j] > 0) last++;
            ans[last+j] = xi[i]+1;
        }
        for(int j=xi[i]; j<N-1; j++){
            free.push(xi[i]+1);
        }
        last += xi[i];
    }

    int s = free.size();
    for(int i=0; i<s; i++){
        int x = free.front();
        free.pop();
        while(ans[last+i] > 0){
            last++;
        }
        if(last+i < X[x-1]){
            cout << "No" << endl;
            return 0;
        }
        ans[last+i] = x;
    }

    cout << "Yes" << endl;
    cout << ans[0];
    for(int i=1; i<ans.size(); i++){
        cout << " " << ans[i];
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 2688
S=input()[::-1]
while True:
  if S[0:5]=='maerd' or S[0:5]=='esare' :
    S= S[5::]
  elif S[0:7]=='remaerd' :
    S=S[7::]
  elif S[0:6]=='resare':
    S=S[6::]
  else:
    print('NO')
    break
  if len(S)==0:
    print('YES')
    break



Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <chrono>
using namespace std;

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

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

    vector<int>::iterator minIt = min_element(a.begin(), a.end());
    int min = *minIt;
    int minIndex = distance(a.begin(), minIt);
    vector<int>::iterator maxIt = max_element(a.begin(), a.end());
    int max = *maxIt;
    int maxIndex = distance(a.begin(), maxIt);

    if ( min >= 0 ) {
        int M = 0;
        for ( int i = 0; i < n; i++ ) {
            M += a[i];
        }
        M -= 2 * min;

        cout << M << endl;
        int sub = min;
        int count = 0;
        for ( int i = 0; i < n; i++ ) {
            if (i == minIndex) continue;
            if (count == n - 2) {
                cout << a[i] << " " << sub << endl;
                break;
            }
            cout << sub << " " << a[i] << endl;
            sub -= a[i];
            count += 1;
        }
    }
    else if ( max <= 0 ) {
        int M = 0;
        for ( int i = 0; i < n; i++ ) {
            M += fabs(a[i]);
        }
        M -= 2 * fabs(max);

        cout << M << endl;
        int sub = max;
        for ( int i = 0; i < n; i++ ) {
            if (i == maxIndex) continue;
            cout << sub << " " << a[i] << endl;
            sub -= a[i];
        }
    }
    else {
        int M = 0;
        for ( int i = 0; i < n; i++ ) {
            M += fabs(a[i]);
        }
        cout << M << endl;

        int sub = min;
        for ( int i = 0; i < n; i++ ) {
            if ( a[i] < 0 || i == maxIndex) continue;
            cout << sub << " " << a[i] << endl;
            sub -= a[i];
        }
        int sub2 = max;
        cout << sub2 << " " << sub << endl;
        sub2 -= sub;
        for ( int i = 0; i < n; i++ ) {
            if ( a[i] >= 0 || i == minIndex) continue;
            cout << sub2 << " " << a[i] << endl;
            sub2 -= a[i];
        }
    }

    return 0;
}

Measured memory_bytes: 2304
import numpy as np
import sys

input = sys.stdin.readline

A,B,C,X,Y = map(int,input().split())


ans = A*X+B*Y
acnt = X
bcnt = Y

for i in range(max(X,Y)):
    tmp = ans

    if acnt > 0:
        acnt-=1
        tmp -= A
    if bcnt > 0:
        bcnt-=1
        tmp -= B

    ans =min(ans, tmp + C*2)

print(ans)




Measured memory_bytes: 19112
#include <iostream>
using namespace std;
int gcd(int p,int q);

int main(void){
    int n;
    long int sum=0;
    
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int l=gcd(i,j);
            for (int k=1;k<=n;k++){
                sum+=gcd(l,k);
            }
        }
    }
    
    cout<<sum<<endl;
}

int gcd(int p,int q){
    if(p%q==0) return q;
    else return gcd(q,p%q);
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

vector<int> cal(Graph G,int p,int N) {
    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化

    queue<int> que;

    // 初期条件 (頂点 p を初期ノードとする)
    dist[p] = 0;
    que.push(p); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {  //nv = next v
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    return dist;
}


int main() {
    int N,X,Y;
    cin >> N >> X >> Y;
    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);
    map<int,int> mp;
    for (int i = 0;i<N;i++) {
        vector<int> d = cal(G,i,N);
        for (int j = 0;j<N;j++) {
            mp[d.at(j)]++;
        }
    }
    for (int i = 1;i<N;i++) {
        cout << mp[i]/2 << endl;
    }
}

Measured memory_bytes: 640
'''
.append(要素) リストに要素を追加 
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul

N = int(stdin.readline().rstrip())
nums = [int(s) for s in stdin.readline().rstrip().split()]
nums.sort()
check = True
for el in range(N):
    if el == N - 1:
        break
    if nums[el] == nums[el + 1]:
        print('NO')
        check = False
        break
if check:
    print('YES')


Measured memory_bytes: 79648
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (;;) {
        int n; cin >> n;
        if (n == 0) break;
        int A[26] = {};
        int maxi = 0, maxi2 = 1;
        vector<char> X(n); for (auto &x : X) cin >> x;
        for (int i = 0; i < n; i++) {
            int idx = X[i] - 'A';
            A[idx]++;
            if (idx == maxi) {}
            else if (idx == maxi2 && A[idx] > A[maxi]) {
                swap(maxi, maxi2);
            } else if (A[idx] > A[maxi]) {
                maxi2 = maxi;
                maxi = idx;
            } else if (A[idx] > A[maxi2]) {
                maxi2 = idx;
            }
            if (A[maxi] > A[maxi2] + (n-1-i)) {
                cout << (char)('A'+maxi) << ' ' << i+1 << '\n';
                goto NEXT;
            }
        }
        cout << "TIE\n";
        NEXT:;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, long long T, std::vector<long long> A, std::vector<long long> B){
  vector<pair<long long, long long>> c;
  for (int i = 0; i < N; ++i) {
    c.emplace_back(A[i], B[i]);
  }
  sort(c.begin(), c.end());
  vector<vector<long long>> dp(N, vector<long long>(T, 0));
  if (c[0].first < T) {
    dp[0][c[0].first] = c[0].second;
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j+c[i].first < T; ++j) {
      dp[i][j+c[i].first] = max(dp[i-1][j] + c[i].second, dp[i-1][j+c[i].first]);
    }
  }
  long long last = 0;
  long long ret = 0;
  for (int i = N-1; i >= 0; --i) {
    for (int j = 0; j < T; ++j) {
      ret = max(dp[i][j]+last, ret);
    }
    last = max(c[i].second, last);
  }
  ret = (last, ret);
  std::cout << ret << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long T;
  scanf("%lld",&T);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
    scanf("%lld",&B[i]);
  }
  solve(N, T, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 70784
import java.io.*;
import java.util.*;
import java.math.*;


public class Main
{

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n+1];
        long num[] = new long[n+1];
        for(int i=1;i<=n;i++){
            arr[i] = sc.nextInt();
            num[arr[i]]++;
        }
        long ans = 0;
        for(int i=1;i<=n;i++){
            // System.out.println(num[i]);
            ans += num[i]*(num[i]-1)/2;
        }
        // System.out.println(ans);
        for(int i=1;i<=n;i++){
            long x = ans - (num[arr[i]] - 1);
            System.out.println(x);
        }
    }

}


Measured memory_bytes: 94996
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,k;cin>>n>>k;
  vi x(n);
  rep(i,n)cin>>x[i];
  int ans=0;
  rep(i,n){
    int a=x[i];
    int b=abs(k-x[i]);
    if(a>b)ans+=b*2;
    else ans+=a*2;
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    str A = "AtCoder", s, C = "Contest";
    cin >> A >> s >> C;
    cout << 'A' << s.at(0) << 'C' << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,x;
    cin>>a>>b>>c>>x;

    int count=0;

    for (int i=0;i<=a;i++) {
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50==x){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans = 1000;
ll N;


int main(void) {
    scanf("%lld", &N);
    for (ll i = 1; i*i <= N; i++) {
        if ( N % i != 0) continue;
        ll j = N / i;
        string s = to_string(i);
        string t = to_string(j);
        ans = min(ans, max((int)s.size(), (int)t.size()));
    }
   

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

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int N=get_int();
    cout<<N/3<<endl;
    return 0;
}

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

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

using namespace std;

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;


int main() {  
  int a, b, x;
  cin >> a >> b;
  if ((a+b)%2 == 0){
    x = (a+b)/2;
  }
  else{
    x = (a+b)/2 + 1;
  }
  cout << x << endl;
  
}




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

using namespace std;

const int MAX_N = 2000;

int N, A[MAX_N];
unsigned long long K;

int main(){
    
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    unsigned long long ans = 0;
    unsigned long long ansA = 0;
    unsigned long long ansB = 0;
    
    unsigned long long KK = ((K*(K+1))/2)%1000000007;
    unsigned long long KKK = ((K*(K-1))/2)%1000000007;
    
    
    for (int i = 0; i < N; i++) {
        ansA = 0;
        ansB = 0;
        
        for (int j = 0; j < i; j++) {
            if (A[j] < A[i]) {
                ansA += 1;
            }
        }
        
        
        for (int j = i+1; j < N; j++) {
            if (A[i] > A[j]) {
                ansB += 1;
            }
        }
        
        
        ans += ansB * KK;
        
        
        ans += ansA * KKK;
        
        
        ans = ans % 1000000007;
        
        
                     
                    
        
    }
    
    ans = ans % 1000000007;
    
    cout << ans << endl;
    
    
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	printf("%d\n",a[2]*10+a[1]+a[0]);
	return 0;
} 

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll X, Y; cin >> X >> Y;
  string result = abs(X-Y)>1 ? "Alice" : "Brown";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
  int x[90000],i=0,Count=0;
	
	while(1){
		i++;
		Count++;
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
	}
	for(i=1;i<Count;i++){
		printf("Case %d: %d\n",i,x[i]);
	}
  
  return 0;
}

Measured memory_bytes: 644
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll r;

int main()
{
  std::cin >> r;

  std::cout << 3*r*r << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<std::pair<int, int>> a(n);
	for(int i = 0; i < n; i++) {
		int x, l;
		std::cin >> x >> l;
		a[i] = {x-l, x+l};
	}
	std::sort(a.begin(), a.end(), [](std::pair<int, int> p1, std::pair<int, int> p2) { return p1.second < p2.second; });
	int ans = 0;
	for(int i = 0, r = -1e9; i < n; i++) {
		if(a[i].first >= r) {
			r = a[i].second;
			ans++;
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include "boost/multiprecision/cpp_int.hpp"
using ll = long long;
using ull = unsigned long long;
namespace mp = boost::multiprecision;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	std::string s; std::cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if ((i + 1) % 2 == 1)std::cout << s[i];
	}

	return 0;

}

Measured memory_bytes: 592
'use strict'

const main = (input) => {
    const S = input.split('\n')[1].split('')
    let max = 0
    let current = 0
    S.forEach(v => {
        if(v === 'I'){
            current++
        }
        if(v === 'D'){
            current--
        }
        if(max < current){
            max = current
        }
    })
    console.log(max)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
def main():
    A, B, C = map(int, input().split())
    A, B, C = sorted([A, B, C])
    if A == B == C:
        return 0
    elif B == C:
        if (B-A) % 2 == 0:
            return (B-A) // 2
        else:
            return (B-A+1) // 2 + 1
    elif A == B:
        return (C-B)
    else:
        if (B-A) % 2 == 0:
            return (B-A)//2 + C-B
        else:
            return (B-A+1)//2 + (C-B) + 1

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
n = int(input())
a = sorted(list(map(int, input().split())))

if n%2 == 0: # 人数が偶数の場合に不整合があるか確認
  for i in range(0,n,2):
    if a[i] != i+1 or a[i] != a[i+1]:
      print(0)
      exit()
else: # 人数が奇数の場合に不整合があるか確認
  if a[0] != 0: # 差分が0存在していることを確認
    print(0)
    exit()
  else:
    for i in range(1,n,2):
      if a[i] != i+1 or a[i] != a[i+1]:
        print(0)
        exit()

ans = 1
for i in range(n//2):
  ans = ans * 2 % (10**9+7) # 組み合わせとしては同じ差分の値を入れ替える2択になるので、結果を2倍にする
print(ans)

Measured memory_bytes: 20464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll cnt(ll n) {
    if(n == 1) return 1;
    return 2 * cnt(n / 2) + 1;
}

int main() {
    ll H;
    cin >> H;
    cout << cnt(H) << endl;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

// LCM : find Least Common Multiple (LCM) via GCD
func LCM(a, b int, integers ...int) int {
	result := a / GCD(a, b) * b

	for i := 0; i < len(integers); i++ {
		result = LCM(result, integers[i])
	}

	return result
}

func gcd(a, b int) int {
	if b != 0 {
		return gcd(b, a%b)
	}
	return a
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func x2(n int) int {
	ret := 0
	for n%2 == 0 {
		ret++
		n /= 2
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	//
	for i := 0; i < N; i++ {
		if a[i]%2 == 1 {
			out(0)
			return
		}
		a[i] /= 2
	}

	t := x2(a[0])
	// out(t)
	a[0] >>= uint(t)
	for i := 1; i < N; i++ {
		if x2(a[i]) != t { // 偶数なので必要ないのでは
			out(0)
			return
		}
		a[i] >>= uint(t)
	}

	M >>= uint(t)

	// out(a)

	//l := LCM(1, 1, a...)
	l := 1
	for i := 0; i < N; i++ {
		l = lcm(l, a[i])
		if l > M {
			out(0)
			return
		}
	}

	//	out(l)

	//S	out(l, M)
	M /= l
	out((M + 1) / 2)
}


Measured memory_bytes: 3072
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
# 相手の手に対して勝ったときの得点
rsp_dic = {"r":P,"s":R,"p":S}
# 相手の手に対して
rsp_dic2 = {0:P,1:R,2:S}
# 自分の手に対して勝てる相手の手
rsp_win = ["s","p","r"]
# 相手の手に対して勝てる自分の手
rsp_lose = {"r":2,"s":0,"p":1}

anslist = [0] * K

modcount = [N//K]*K
for i in range(1,N%K+1):
    modcount[i] += 1

for k in range(K):
    count = modcount[k]
    dp = [[0,0,0] for _ in range(count+1)]
    for i in range(1, count+1):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2])
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1])
        if k != 0:
            dp[i][rsp_lose[T[(i-1) * K + k - 1]]] += rsp_dic[T[(i-1) * K + k - 1]]
        else:
            dp[i][rsp_lose[T[i * K + k - 1]]] += rsp_dic[T[i * K + k - 1]]

    anslist[k] = max(dp[-1])

print(sum(anslist))

Measured memory_bytes: 58352
package main

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

func main() {
	N := ReadInt()
	b := ReadInts(N)
	ans := make([]int, N)
	for i := N; i >= 1; i-- {
		ok := false
		for j := i; j >= 1; j-- {
			if b[j-1] == j {
				ans[i-1] = j
				c := []int{}
				c = append(c, b[:j-1]...)
				c = append(c, b[j:]...)
				b = c
				ok = true
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			return
		}
	}
	for i := 0; i < N; i++ {
		fmt.Println(ans[i])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1984
#include <vector>
#include <iostream>
using namespace std;
int n, a;
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	vector<int> x(2 * n); int l = n, r = n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i % 2 == 0) x[r++] = a;
		else x[--l] = a;
	}
	if (n % 2 == 0) for (int i = l; i < r; i++) cout << x[i] << ' ';
	else for (int i = r - 1; i >= l; i--) cout << x[i] << ' ';
	return 0;
}

Measured memory_bytes: 3712
// abc134c: Exception Handling
#include <stdio.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define in(n) scanf("%d",n)
#define outi(d) printf("%d\n",d)

int main(){
  int n,a[200000],maxix1,maxix2;

  in(&n);

  maxix1 = maxix2 = -1;
  rep(i,n){
    in(a+i);
    if(maxix1<0 || a[maxix1]<a[i]) maxix1 = i;
    if(maxix1!=i && (maxix2<0 || a[maxix2]<a[i])) maxix2 = i;
  }

  rep(i,n) outi(a[i]==a[maxix1]? a[maxix2]: a[maxix1]);
  return 0;
}

Measured memory_bytes: 2304
// %%
import java.util.*;
import java.io.PrintWriter;

// %%
public class Main {

    private static int N;
    private static int K;
    private static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        load();
        solve();
        pw.flush();
    }

    private static void load() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
    }

    private static void solve() {
        if (K > (N - 1) * (N - 2) / 2) {
            pw.println(-1);
            return;
        }

        int cnt = N - 1 + (N - 1) * (N - 2) / 2 - K;
        pw.println(cnt);

        for (int v = 1; v <= N; v += 1) {
            for (int w = v + 1; w <= N; w += 1) {
                // pw.println(String.format("%d %d", v, w));
                pw.print(v);
                pw.print(' ');
                pw.println(w);
                cnt -= 1;
                if (cnt == 0) {
                    return;
                }
            }
        }
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())


/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l
　 　　　／` ミ＿x ノ   Zzz...
　　 　 /　 　　  |   コード見ちゃだめ！！
　　　 /　 ヽ　　 ﾉ
　 　 │　　|　|　|
　／￣|　　 |　|　 |
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

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

string s; int n, ans;

int main(){
	cin>>n>>s;
	for (int i=0;i<1000;i++){
		int k[3]={i/100,(i/10)%10,i%10};
		int count=0;
		for (int j=0;j<n;j++) {
			if (s[j]==('0'+k[count]))count++;
			if (count==3) break;
		}
		if(count==3) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    int n, x;

    cin >> n >> x;

    if (n * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< int > t(n), x(n), y(n);
  for (int i=0; i<n; ++i) cin >> t[i] >> x[i] >> y[i];
  int pt=0, px=0, py=0;
  for (int i=0; i<n; ++i) {
    int dist = abs(x[i]-px) + abs(y[i]-py);
    if (dist > t[i]-pt || (t[i]-pt-dist)%2==1) {
      cout << "No" << endl;
      return 0;
    }
    pt=t[i]; px=x[i]; py=y[i];
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
import sys
# input = sys.stdin.readline
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        x, y = map(int, input().split())
        yield x, y

def main():
    n, m = map(int, input().split())
    
    stu = list(readlines(n))
    check = list(readlines(m))
    
    def distances(a, b):
        for i, cd in enumerate(check, 1):
            c, d = cd
            yield abs(a - c) + abs(b - d), i

    for a, b in stu:
        yield str(min(distances(a, b))[1])



print("\n".join(main()))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int parent(int p) {
  return (p+1)/2-1;
}

int left(int p) {
  return (p+1)*2-1;
}

int right(int p) {
  return (p+1)*2;
}

int main() {
  int H; cin >> H;
  vector<int> heap(H);
  for (int i = 0; i < H; i++) {
    cin >> heap[i];
  }
  for (int i = 0; i < H; i++) {
    cout << "node " << i+1 << ": key = " << heap[i] << ", ";
    if (i != 0) {
      cout << "parent key = " << heap[parent(i)] << ", ";
    }
    if (left(i) < H) {
      cout << "left key = " << heap[left(i)] << ", ";
    }
    if (right(i) < H) {
      cout << "right key = " << heap[right(i)] << ", ";
    }
    cout << endl;
  }
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
import math
from functools import reduce
N,X = input().split()

x_list = input().split()

x_list_X  = [abs(int(i)-int(X)) for i in x_list]

# N,Mの最大公約数　
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)

print(reduce(gcd, x_list_X))

Measured memory_bytes: 14744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	double a, b;
	cin >> a >> b;
	cout << fixed << setprecision(10) << a * b / 3.305785 << endl;
}


Measured memory_bytes: 3280
from fractions import gcd
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ar = a[::-1]
    lgcds = [1]*n
    rgcds = [1]*n
    lgcd, rgcd = a[0], ar[0]
    lgcds[0] = rgcd
    lgcds[1] = lgcd
    rgcds[n-1] = lgcd
    rgcds[n-2] = rgcd
    for i in range(2, n):
        lgcd = gcd(lgcd, a[i-1])
        rgcd = gcd(rgcd, ar[i-1])
        lgcds[i] = lgcd
        rgcds[n-1-i] = rgcd
    ans = 1
    for i in range(n):
        gi = gcd(lgcds[i], rgcds[i])
        if gi > ans:
            ans = gi
    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 89580
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    RREP(i, 1, 10) q.push(i);
    RREP(i, 0, k-1) {
        ll s = q.front();
        q.pop();
        RREP(j, -1, 2) {
            ll add = (s % 10) +j;
            if (add>= 0 && add <= 9) q.push(s*10 + add);
        }
    }
    cout << q.front() << endl;
    
}





// void rec(int d, ll val, vector<ll> &all) {
//     all.push_back(val);

//     if (d == 10) return;

//     for(int i = -1; i <= 1; i++) {
//         int add = (val % 10) + i;
//         if (add >= 0 && add <= 9) rec(d+1, val*10+add, all);
//     }
// }

// int main() {

//     int k;
//     cin >> k;

//     vector<ll> all;
//     for(int i = 1; i < 10; i++) {
//         rec(1, i, all);
//     }

//     sort(ALL(all));

//     cout << all[k-1] << endl;

//     return 0;
// }

Measured memory_bytes: 1792
import sys

N = int(input())

co = []
x, y = map(int, input().split())
co.append((x, y))
Amod = (x + y) % 2
flag = True
max_co = abs(x) + abs(y)
for i in range(N - 1):
    x, y = map(int, input().split())
    co.append((x, y))

    if(Amod != (x + y) % 2):
        flag = False

    tmp = abs(x) + abs(y)
    max_co = max(max_co, tmp)

if(flag is False):
    print(-1)
    sys.exit()

ex2 = [1, 2, 4, 8, 16, 32]
expo = 32
# print(maxxy)
while(expo < max_co):
    expo *= 2
    ex2.append(expo)


ans_list = []
for x, y in co:
    if Amod == 0:
        x -= 1
        ans = "R"
    else:
        ans = ""

    for arm in reversed(ex2):
        # print("present", x, y)
        if abs(x) > abs(y):
            if x > 0:
                x -= arm
                ans = "R" + ans
            else:
                x += arm
                ans = "L" + ans
        else:
            if y > 0:
                y -= arm
                ans = "U" + ans
            else:
                y += arm
                ans = "D" + ans
    # print(x, y)

    ans_list.append(ans)

if Amod == 0:
    ex2.append(1)

print(len(ex2))
arm = ""
for a in ex2:
    arm += " " + str(a)
print(arm[1:])
for a in ans_list:
    print(a)

Measured memory_bytes: 3388
n, k = map(int, input().split())
lst = list(map(int, (input().split())))
lst = [_ - 1 for _ in lst]

visited = [0] * n
i = 0
now = 0
while k > i:
    if visited[now] == 0:
        i += 1
        visited[now] = i
        now = lst[now] 
    else:
        break

lp = (i + 1) - visited[now]
st = i - lp
k_bk = k - st
k_bk = k_bk // lp
lft = k - (k_bk * lp + st)

if lft == 0:
    print(now+1)
else:
    for _ in range(lft):
        now = lst[now]
    print(now+1)


Measured memory_bytes: 32252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  string s, t;
  cin >> s >> t;
  if(t.sz != s.sz + 1)cout << "No\n";
  else {
    t.erase(t.end() - 1);
    if(s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
  }


  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

void small(int x, int y, int a[10][10]) {
	a[x][y] += 1;
	if(x-1>=0) a[x-1][y] += 1;
	if(x+1<=9) a[x+1][y] += 1;
	if(y-1>=0) a[x][y-1] += 1;
	if(y+1<=9) a[x][y+1] += 1;
}

void mid(int x, int y, int a[10][10]) {
	small(x, y, a);
	if(x-1>=0 && y-1>=0) a[x-1][y-1] += 1;
	if(x+1<=9 && y-1>=0) a[x+1][y-1] += 1;
	if(x-1>=0 && y+1<=9) a[x-1][y+1] += 1;
	if(x+1<=9 && y+1<=9) a[x+1][y+1] += 1;
}

void large(int x, int y, int a[10][10]){
	mid(x,y,a);
	if(x-2>=0) a[x-2][y] += 1;
	if(x+2<=9) a[x+2][y] += 1;
	if(y-2>=0) a[x][y-2] += 1;
	if(y+2<=9) a[x][y+2] +=1 ;
}


int main(void) {

	int area[10][10] = {0};
	int x, y, size;
	
	while( scanf("%d,%d,%d", &x, &y, &size) != EOF ) {
		if(size == 1) small(x, y, area);
		else if(size == 2) mid(x, y, area);
		else if(size == 3) large(x, y, area);
		else{continue;}
	}
	
	int count=0, max=0;
	int i,j;
	
	for(i=0; i<=9; i++) {
		for(j=0; j<=9; j++) {
			if(area[i][j] == 0) count++;
			if(area[i][j] > max)  max = area[i][j];
		}
	}
	
	printf("%d\n%d\n", count, max);
	
	return 0;
}
	

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)
template<class T, class U>inline bool chmin(T &a, U const &b) { if(b<a){ a=b;return 1; } return 0; }

int N, M, a, b;
long long c;
bool flag;
long long graph[1000];
vector<tuple<int, int, long long>> edge;

int main() {
  cin >> N >> M;
  rep(i, M){
    cin >> a >> b >> c;
    a--; b--;
    edge.push_back(make_tuple(a, b, -c));
  }

  rep(i, N) graph[i] = INF;
  graph[0] = 0;

  rep(i, N*2){
    flag = false;
    for (auto e : edge){
      a = get<0>(e); b = get<1>(e); c = get<2>(e);
      if (chmin(graph[b], graph[a]+c)){
        if (b==N-1) flag = true;
      }
    }
  }

  if (flag) cout << "inf" << endl;
  else cout << -graph[N-1] << endl;
  return 0;
}

Measured memory_bytes: 256