akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scn = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Solution Start

        // D-Road to Millionaire
        int n = scn.nextInt();
        long m = 1000;
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = scn.nextInt();
        }


        for (int i = 0; i < (n - 1); i++) {
            long stocks = 0;
            if (a[i] < a[i + 1]) stocks = m / a[i];
            m += (a[i + 1] - a[i]) * stocks;
        }
        out.println(m);
        /*
        // C-Marks
        int n = scn.nextInt();
        int[] a = new int[n];
        int k = scn.nextInt();
        for (int i = 0; i < n; i++) {
            a[i] = scn.nextInt();
        }

        for (int i = k; i < n; i++) {
            if (a[i] > a[i - k]) out.println("Yes");
            else out.println("No");
        }
        */
        //Solution end
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


Measured memory_bytes: 32904
'use strict'
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  let line1 = input[0].split(" ");
  
  let A = line1[0];
  let B = line1[1];
  let C = line1[2];

  let cnt = 0;

  if(A === B) cnt++;
  if(B === C) cnt++;
  if(C === A) cnt++;

  if(cnt === 1) console.log("Yes");
  else console.log("No");

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if (ls[i]+ls[j] > ls[k]) and ls[i]!=ls[j] and ls[i]!=ls[k] and ls[k]!=ls[j] :
                ans += 1
print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len, a, b, c;
	ll B, C, D, N, M, K,num_R,num_G,num_B;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count=0, W;
	ll **dp;
	char S[200000];
	int ans;

	
	cin >> N >> M;

	vector<int> A(N);

	for (i = 0; i < N; i++){
		cin >> A[i];
		sum += A[i];
	}

	for (i = 0; i < N; i++){
		if (A[i] * 4 * M >= sum){
			count++;
		}

	}
	if (count >= M)
	cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;


}
    

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

int main() {
	int a[100],n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for (int i = n-1; i >= 0; i--){
		cout << a[i];
		if(i != 0){
			cout << " ";
		} else {
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include<stdio.h>

#define MAX 1000

int main() {
    //変数の宣言
    int n, hako[MAX]; //入力用
    int i; //出力用
    
    //入力
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &hako[i]);
    }
    
    //出力
    for (i=n-1; i>0; i--) {
        printf("%d ", hako[i]);
    }
    
    printf("%d\n", hako[0]);
    
    return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+10;
const int inf = 0x3f3f3f3f;
const int MOD = 993244853;
const ll INF = 1000000000000000010LL;

const int MAXN = 200010;
const int MAXK = 62;

int n;
ll a[MAXN];

int main() {	
	scanf("%d",&n);
	int m = n/2;
	if(n%2 == 0)
		m--;
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_mp1
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
    fast();
    int n,v,l,i,j,m,p,f;
    cin>>n;
    int a[n],dp[n];
    cin>>a[0]>>a[1];
    dp[0]=0;
    dp[1]=fabs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        cin>>a[i];
        dp[i]=min(((fabs(a[i]-a[i-2]))+dp[i-2]),(fabs(a[i]-a[i-1])+dp[i-1]));
    }
    cout<<dp[n-1];
}

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

using namespace std;
int X,N;
int p[4000];
int main()
{
  cin>>X>>N;
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p,p+N);
  int soe=0;
  int ans=0;
  for(int i=1;i<102;i++){
    bool flag=true;
    for(int j=0;j<101;j++){
      if(p[j]==i){
        flag=false;
      }
    }
    if(flag&&abs(i-X)<abs(ans-X)){
      ans=i;
    }
  }
  cout<<ans;
  return 0;
}





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

int i,j,k;
int a,b,c,flag[304],n;
typedef struct result{
	int x,y,z,r;
}RESULT;
RESULT w[1005];

int main(){
	scanf("%d %d %d",&a,&b,&c);
	while(a!=0 && b!=0 && c!=0){
		for(i=1;i<=a+b+c;i++)flag[i]=2;
		scanf("\n%d",&n);
		for(i=1;i<=n;i++){
			scanf("%d %d %d %d",&(w+i)->x,&(w+i)->y,&(w+i)->z,&(w+i)->r);
			if((w+i)->r==1){
				flag[(w+i)->x]=1;
				flag[(w+i)->y]=1;
				flag[(w+i)->z]=1;
			}
		}
		
		for(i=1;i<=n;i++){
			if((w+i)->r==0){
				if(flag[(w+i)->x]==1 && flag[(w+i)->y]==1)flag[(w+i)->z]=0;
				if(flag[(w+i)->y]==1 && flag[(w+i)->z]==1)flag[(w+i)->x]=0;
				if(flag[(w+i)->z]==1 && flag[(w+i)->x]==1)flag[(w+i)->y]=0;
			}
		}
		for(i=1;i<=a+b+c;i++)printf("%d\n",flag[i]);
		
		scanf("%d %d %d",&a,&b,&c);
	}
	return 0;
}

Measured memory_bytes: 0
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static vector<sl> Ai;
static const sl MOD = 1000000007;

/*

naive:
  sl res = 0;
  FOR0(i, N - 1) {
    FORi(j, i + 1, N) {
      res += Ai[i] ^ Ai[j];
      cout << (Ai[i] ^ Ai[j]) << endl;
      res %= MOD;
    }
  }
  cout << res << endl;
*/


void solve(void) {
  vector<sl> count_by_bits(60, 0);
  sl res = 0;
  FOR0(k, 60) {
    FOR0(i, N) {
      if ((Ai[i] & (1LL << k)) != 0) {
        count_by_bits[k]++;
      }
    }
  }
  FOR0(k, 60) {
    sl t = (1LL << k) % MOD;
    t = (t * count_by_bits[k]) % MOD;
    t = (t * (N - count_by_bits[k])) % MOD;
    res += t;
    res %= MOD;
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  Ai.resize(N);
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

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

int gcd(int x, int y, int z){
  int d,e;
  d=1;
  e=1;
  while(e<=x&&e<=y&&e<=z){
    if(x%e==0&&y%e==0&&z%e==0)
    d=e;
    e++;
  }
  return d;
}

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

Measured memory_bytes: 3624
q = int(input())
from math import sqrt
l = list(range(2,100000))
msqrt = int(sqrt(100000))
first = l[0]
prime = []
like = []
import bisect as bs
while first < msqrt:
    prime.append(first)
    l = list(filter(lambda x: x%first != 0, l))
    h = (first+1)//2
    ix = bs.bisect_left(prime, h)
    if prime[ix] == h:
        like.append(first)
    first = l[0]
prime.extend(l)
for ll in l:
    h = (ll+1)//2
    ix = bs.bisect_left(prime, h)
    if prime[ix] == h:
        like.append(ll)
for i in range(q):
    l, r = (int(x) for x in input().split())
    print(bs.bisect_right(like, r)-bs.bisect_left(like, l))


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

struct point {
	ldbl x;
	ldbl y;

	point() = default;
	point(ldbl x, ldbl y):
		x(x),
		y(y)
	{}

	point operator+(const point &ri) const {
		return point(x + ri.x, y + ri.y);
	}
};

struct circuit {
	point p;
	ldbl r;

	circuit() = default;
	circuit(point p, ldbl r):
		p(p),
		r(r)
	{}
};

llong N;
vector<point> p;

circuit get_circuit(point p1, point p2, point p3) {
	ldbl a = p1.x - p2.x,
		 b = p1.y - p2.y,
		 c = p2.x - p3.x,
		 d = p2.y - p3.y,
		 x1 = p1.x*p1.x + p1.y*p1.y,
		 x2 = p2.x*p2.x + p2.y*p2.y,
		 x3 = p3.x*p3.x + p3.y*p3.y,
		 x1x2 = x1 - x2,
		 x2x3 = x2 - x3,
		 eps = 1e-8;

	ldbl waru = 1.0 / (2.0l * (a*d - b*c + eps));

	point ret;
	ret.x = waru * (d*x1x2 - b*x2x3);
	ret.y = waru * (-c*x1x2 + a*x2x3);

	return circuit(ret, (p1.x - ret.x)*(p1.x - ret.x) + (p1.y - ret.y)*(p1.y - ret.y));
}

circuit get_circuit(point p1, point p2) {
	point res((p1.x + p2.x)/2.0, (p1.y + p2.y)/2.0);

	return circuit(res, (p1.x - res.x)*(p1.x - res.x) + (p1.y - res.y)*(p1.y - res.y));
}

ldbl get_distance(point p1, point p2) {
	return (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
}

ldbl solve() {
	ldbl ret = inf<double>;

	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			circuit c;
			bool check;

			c = get_circuit(p[i], p[j]);
			check = true;
			for (int k = 0; k < N; ++k) {
				if (k == i || k == j) continue;
				ldbl d = get_distance(c.p, p[k]);
				if (d > c.r) check = false;
			}
			if (check) {
				ret = min(ret, c.r);
				continue;
			}

			for (int k = j + 1; k < N; ++k) {
				c = get_circuit(p[i], p[j], p[k]);
				check = true;
				for (int h = 0; h < N; ++h) {
					if (h == i || h == j || h == k) continue;
					ldbl d = get_distance(c.p, p[h]);
					if (d > c.r) check = false;
				}
				if (check) {
					ret = min(ret, c.r);
				}
			}
		}
	}

	return sqrtl(ret);
}

int main() {
	cin >> N;
	p.resize(N);
	for (auto &in: p) {
		cin >> in.x >> in.y;
	}

	cout << fixed << setprecision(30) << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var input = input.split(" ").map(val => parseInt(val, 10));

  var a = input[0];
  var b = input[1];
  var t = input[2] + 0.5;

  var result =Math.floor(t / a) * b; 


  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int MAX = 110000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> nums(N);
    for (int i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        nums.at(i) = A;
    }
    COMinit();
    sort(nums.begin(), nums.end());
    if(nums.at(0) < 0){
        ll firstNum = nums.at(0);
        for(int i = 0; i < N; i++){
            nums.at(i) += firstNum;
        }
    }
    ll answer = 0;
    for (int i = K - 1; i < N; i++)
    {
        answer = (answer + COM(i, K - 1) * nums.at(i)) % MOD;
    }
    ll min = 0;
    for (int i = 0; i < N - K + 1; i++)
    {
        min = (min + ((COM(N - i - 1, K - 1) * nums.at(i)) % MOD)) % MOD;
    }
    answer = (answer - min + MOD) % MOD;
    cout << answer << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  if(n%2==0){
    char c=s[n/2];
    int ans=n/2;
    for(int i=0;i<n/2;i++){
      if(s[n/2-i-1]==c&&s[n/2+i]==c){
        ans++;
      }
      else{
        break;
      }
    }
    cout << ans << endl;
  }
  else{
    char c=s.at(n/2);
    int ans=n/2+1;
    for(int i=0;i<n/2;i++){
      if(s[n/2-i-1]==c&&s[n/2+i+1]==c){
        ans++;
      }
      else{
        break;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a == 1) {
			a += 13;
		}
		if(b == 1) {
			b += 13;
		}

		if(a > b) {
			System.out.println("Alice");
		}else if(a < b){
			System.out.println("Bob");
		}else {
			System.out.println("Draw");
		}
}
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
	string s = in<string>();
	string r(s);
	reverse(ALL(r));

	int n = s.size();
	rep(i, n) {
		if (r[i] == 'b') {
			r[i] = '0';
		}
		if (r[i] == 'p') {
			r[i] = '1';
		}
	}

	rep(i, n) {
		if (r[i] == 'd') {
			r[i] = 'b';
		}
		if (r[i] == 'q') {
			r[i] = 'p';
		}
	}

	rep(i, n) {
		if (r[i] == '0') {
			r[i] = 'd';
		}
		if (r[i] == '1') {
			r[i] = 'q';
		}
	}

	cout << (r == s ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <numeric>
#include <utility>
#include <set>
#include <queue>
#include <cstring>
#include <bitset>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef struct segment segment;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>

int main()
{
  string s; cin >> s;
  
  int n = s.size();
  
  vector<int> total[1<<(n-1)];
  
  for(int i=0;i<(1<<(n-1));i++){
    
    for(int j=0;j<n-1;j++){
      if(i & (1<<j)) total[i].pb(j+1);
    }
    //sort(total[i].begin(),total[i].end());
  }
  

  ll ans = 0;
 /* for(int i=0;i<(1<<(n-1));i++){
    for(auto j:total[i]) cout << j;
    cout<<endl;
  }*/
  for(int i=0;i<(1<<(n-1));i++){
    int j = 0;
    ll sum = 0;
    for(int k=0;k<n;k++){
      if(j<total[i].size()&&k==total[i][j]) ans+=sum,sum=s[k]-48, j++;
      else sum*=10,sum+=(s[k]-48);
      
    }
    if(sum) ans+=sum;
  }
  cout<<ans;
  
}

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

//F
int main(void) {
  int n, k, i,q, cou=0, tmp;
  scanf("%d %d %d", &n,&k,&q);
  int a[q],b[n];
  for(i=0; i <n; i++){
    b[i]=0;
  }

  for(i=0; i < q; i++){
    scanf(" %d", &a[i]);
    b[a[i]-1]++;
  }
  for(i=0; i <n; i++){
    if(q-b[i]+1<=k)printf("Yes\n");
    else printf("No\n");
  }
}

Measured memory_bytes: 1280
import java.util.*;
import java.lang.*;

public class Main {
    static int needCoin(int N, int K){
        int c=0;
        while(N<K){
            N *= 2;
            c++;
        }
        return c;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        double ans = 0;
        for(int n=1; n<=N; n++){
            ans += (Math.pow(0.5, needCoin(n,K))/N);
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, total;
  string S;
  char a, b, c;
  cin >> N >> S;
  
  for(int i = 0;i < N - 2;i++){
  a = S.at(i);
  b = S.at(i+1);
  c = S.at(i+2);
    if(a == 'A' && b == 'B' && c == 'C'){
    total++;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int unsigned long long
int32_t main(){

	int n;
	cin>>n;
	vector<int> a;
	a.resize(n);
	int fx=0;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	for(int i=0;i<n;++i){
		fx^=a[i];
	}
	
	vector<int> ans;
	for(int i=0;i<n;++i){

		ans.push_back(fx^a[i]);
	}

	for(auto x:ans){
		cout<<x<<" ";
	}cout<<'\n';

	return 0;
}

Measured memory_bytes: 6852
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.next();

            if(n.Distinct().Count() == 1)
            {
                Console.WriteLine(n);
            }
            else
            {
                for (int i = int.Parse(n); i <= 999; i++)
                {
                    if(i.ToString().Distinct().Count() == 1)
                    {
                        Console.WriteLine(i);
                        return;
                    }
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
	string s;
	cin >> s;
	string res;
	int n = s.size();
	for (int i = 0;i < n;i++) {
		if (i % 2 == 0) {
			res += s[i];
		}
	}
	cout << res << endl;
	
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main(void)
{
	int i,j,len,cnt,cnt1;
	char n[10001];
	
	while(scanf("%s",n)!=EOF){
		cnt=0;
		cnt1=0;
		len=strlen(n);
		for(i=0;i<len;i++){
			if(n[i]=='J' && n[i+1]=='O' && n[i+2]=='I') {
				cnt++;
			}
		}
		printf("%d\n",cnt);
		for(i=0;i<len;i++){
			if(n[i]=='I' && n[i+1]=='O' && n[i+2]=='I') {
				cnt1++;
			}
		}
		printf("%d\n",cnt1);
	}
	
	return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> image(H);
  for(int i=0; i<H; i++){
    cin >> image.at(i);
  }
  for(int i=0; i<H; i++){
    cout << image.at(i) << endl
         << image.at(i) << endl;
  }
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;

int main() {
    string ABCD;
    cin >> ABCD;
    int a = ABCD[0] - '0';
    int b = ABCD[1] - '0';
    int c = ABCD[2] - '0';
    int d = ABCD[3] - '0';
    REP (op1, 0, 2) REP (op2, 0, 2) REP (op3, 0, 2) {
        int res = a;
        if (op1) res += b;
        else res -= b;
        if (op2) res += c;
        else res -= c;
        if (op3) res += d;
        else res -= d;
        if (res == 7) {
            cout << a << (op1 ? '+' : '-') << b << (op2 ? '+' : '-') << c << (op3 ? '+' : '-') << d << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

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

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n && n;){
		vi ls(2*n);
		rep(i,2*n) cin>>ls[i];
		sort(all(ls));
		int sum=0;
		rep(i,n) sum+=ls[i*2];
		cout<<sum<<endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    vector<string> c(h, string(w, 'x'));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int x = i + j;
            int y = i - j + max(h, w);
            x /= d;
            y /= d;
            x %= 2;
            y = (y % 2 + 2) % 2;
            if (x == 0 && y == 0)
                c[i][j] = 'R';
            else if (x == 0 && y == 1)
                c[i][j] = 'G';
            else if (x == 1 && y == 0)
                c[i][j] = 'B';
            else
                c[i][j] = 'Y';
        }
    }
    for (int i = 0; i < h; ++i) {
        cout << c[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll k;
set<ll> lunlun;
bool dfs(ll now, int d) {
    if (d == 0) {
        lunlun.insert(now);
        if (lunlun.size() == k) return true;
        else return false;
    } else {
        ll ld = now % 10;
        for (ll i = max(0LL, ld - 1); i <= min(9LL, ld + 1); i++) {
            if (dfs(now * 10 + i, d - 1)) return true;
        }
        return false;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> k;
    if (k <= 12) cout << k << '\n';
    else {
        int dig = 1;
        while ((ll)lunlun.size() < k) {
            for (int i = 1; i < 10; i++) dfs(i, dig - 1);
            dig++;
        }
    }

    ll i = 1;
    for (ll ans: lunlun) {
        if (i == k) {
            cout << ans << '\n';
            break;
        } else i++;
    }
    return 0;
}


Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 1000005
int n, A[N];
bool cmp(int a, int b){return a > b;}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	sort(A, A + n, cmp);
	int k = 1;
	while (k + 1 <= n && A[k] >= k + 1)
		k++;
	int u = A[k - 1] - k;
	int r = 0;
	while (k + r < n && A[k + r] == k)
  		r++;
	if (u % 2 == 0 && r % 2 == 0)
		puts("Second");
	else
		puts("First");
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	for (auto &i : a) cin >> i;
	sort(a.begin(), a.end());

	ll l = 2*a[0], r = 2*a.back();
	while (l < r)
	{
		ll md = (l + r + 1) >> 1;
		ll cur = 0;
		for (auto i : a)
			cur += a.end() - lower_bound(a.begin(), a.end(), md-i);
		if (cur >= m)
			l = md;
		else
			r = md - 1;
	}

	auto b = a;
	for (int i = 1; i < n; ++i)
		b[i] += b[i-1];

	ll cur = 0, md = l+1, ans = 0;
	for (auto i : a)
	{
		auto it = lower_bound(a.begin(), a.end(), md-i);
		cur += a.end() - it;
		ans += i * (a.end() - it);
		int p = it - a.begin();
		ans += b.back() - ((p==0) ? 0 : b[p-1]);// [p, end)
	}
	ans += (m-cur)*l;
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 1792
import numpy as np
import fractions as fra



n,m=map(int,input().split())
a=np.array([0]*(n+1))
#print(a)
for i in range(m):
    x,y=map(int,input().split())
    a[x]+=1
    a[y]+=1


print(*a[1:],sep="\n")

Measured memory_bytes: 14968
import java.util.*;

public class Main {

	public static boolean isEnd (String str) {
		boolean f = true;
		for (int i = 1; i < str.length(); i++)
			f &= str.charAt(i - 1) == str.charAt(i);
		return f;
	}

	public static char getColor (char a, char b) {

		if ((a == 'r' && b == 'g') || a == 'g' && b == 'r') return 'b';
		if ((a == 'r' && b == 'b') || a == 'b' && b == 'r') return 'g';
		return 'r';

	}

	public static String bfs (String str) {

		if (isEnd(str)) return "0";

		ArrayList<String> pattern = new ArrayList<String>();
		Set<String> memo = new HashSet<String>();

		int step = 1;

		pattern.add(str);
		memo.add(str);

		while (!pattern.isEmpty()) {

			ArrayList<String> next = new ArrayList<String>();
			for (String p : pattern) {
				for (int i = 1; i < p.length(); i++) {
					if (p.charAt(i - 1) != p.charAt(i)) {
						char[] c = p.toCharArray();
						char rep = getColor(p.charAt(i - 1), p.charAt(i));
						c[i - 1] = (c[i] = rep);
						if (isEnd(new String(c))) return "" + step;
						if (!memo.contains(new String(c))) {
							memo.add(new String(c));
							next.add(new String(c));
						}
					}
				}

			}

			step++;
			pattern = next;
		}

		return "NA";
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {

			String str = sc.nextLine();
			if (str.equals("0")) break;
			System.out.println(bfs(str));

		}

	}

}

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

N = lines[0][0]

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

for i in 1..N do
  num_arrival[lines[1][i-1]-1] = i
end

for i in 1..N do
  print num_arrival[i-1].to_s + " "
end

Measured memory_bytes: 12548
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int n,a[1000]={};
	cin>>n;
	for(int i=0;i<2*n;i++){
		cin>>a[i];
	}
	int ans=0;
	sort(a,a+2*n);
	for(int i=0;i<2*n;i+=2){
		ans+=a[i];
	}
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (i <= b && j <= a) cout << 1;
			else if (i <= b) cout << 0;
			else if (j <= a) cout << 0;
			else cout << 1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N = 105;
const int MOD = 1000000007;

int n,m,h[N],w[N];
LL dp[N][N];

int pow_(int x,int y) {///快速幂求 x的y次方
    int ans = 1;
    if(y > 0) {
        while(y) {
            if(y % 2)ans = (LL)ans * x % MOD;
            x = (LL)x * x % MOD;
            y /= 2;
        }
    }
    return ans;
}

int main() {
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++) {
        scanf("%d",&h[i]);
        w[++ m] = h[i];
    }
    sort(w + 1,w + m + 1);///高度排序
    m = unique(w + 1,w + m + 1) - w - 1;///离散化 m是离散化后的长度
    for(int i = 1;i <= n;i ++) {
        h[i] = lower_bound(w + 1,w + m + 1,h[i]) - w;
    }
    dp[0][0]=1;
    for(int i = 1;i <= n;i ++) {
        for(int j = h[i] + 1;j <= h[i - 1];j ++)
            (dp[i][0] += dp[i - 1][j] * 2 % MOD) %= MOD;

        (dp[i][0] += dp[i - 1][0] * 2 % MOD) %= MOD;///交叉或者不交叉

        int d = pow_(2,w[h[i]] - w[h[i-1]]);
        for(int j = 1;j <= min(h[i - 1],h[i]);j ++) {
            dp[i][j] = dp[i - 1][j] * d % MOD;
        }

        for(int j = h[i - 1] + 1;j <= h[i];j ++) {///比前一列高出的部分
            if(j > 1)(dp[i][j] += dp[i - 1][0] * (pow_(2,w[j] - w[j - 1]) - 1) % MOD * 2 % MOD * pow_(2,w[h[i]] - w[j]) % MOD) %= MOD;
            else (dp[i][1] += dp[i - 1][0] * (pow_(2,w[1]) - 2) % MOD * pow_(2,w[h[i]] - w[1]) % MOD) %= MOD;///上一列中无重复的乘上化不超过上一列高度中有重复的
        }
    }
    LL ans = 0;
    for(int i = 0;i <= m;i++)
        (ans += dp[n][i]) %= MOD;
    printf("%lld",ans);
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmin(T &a, T b){
    if(a > b){
        a = b;
        return true;
    }else{
        return false;
    }
}

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

    int n;
    cin >> n;

    vector<string> w(n + 1);
    REP(i, 1, n + 1){
        cin >> w[i];
    }
    w[0].clear();
    w[0].push_back(w[1][0]);

    map< pair<char, char>, int > mp;
    rep(i, n + 1){
        mp[{w[i].front(), w[i].back()}] = i;
    }

    vector< vector<int> > v(26);
    for(auto x : mp){
        v[x.first.first - 'a'].emplace_back(x.second);
    }
    rep(i, 26){
        SORT(v[i]);
    }

    vector<int> cost(n + 1, IINF);
    queue< P > que;
    que.push({0, 0});
    while(!que.empty()){
        P now = que.front();
        que.pop();
        if(!chmin(cost[now.first], now.second)){
            continue;
        }
        for(auto it = upper_bound(v[w[now.first].back() - 'a'].begin(), v[w[now.first].back() - 'a'].end(), now.first) ; it != v[w[now.first].back() - 'a'].end() ; ++it){
            if(cost[*it] > now.second + 1){
                que.push({*it, now.second + 1});
            }
        }
    }

    cout << cost[n] << endl;

    return 0;
}


Measured memory_bytes: 8912
#include <stdio.h>

int fib(int);

int a[50];

int main(void)
{
	int n;
	
	scanf("%d",&n);
	
	printf("%d\n",fib(n));
	
	return 0;
}

int fib(int n){
	
	int i;
	
	a[1]=a[0]=1;
	
	for(i=2; i<=n; i++) {
		a[i] = a[i-1] + a[i-2];
	}
	
	return a[n];
}

Measured memory_bytes: 596
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    xx = list(map(int, input().split()))
    cxx = sorted(xx)
    m0 = cxx[n // 2 - 1]
    m1 = cxx[n // 2]
    for x in xx:
        if x <= m0:
            print(m1)
        else:
            print(m0)

main()


Measured memory_bytes: 25476
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int n, m, a[50], b[50];
bool g[50][50];
bool seen[50];

void dfs(int u) {
    seen[u] = true;

    rep(v, n) {
        if (!g[u][v] || seen[v]) continue;
        dfs(v);
    }
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        int u, v; cin >> u >> v;
        u--; v--;
        a[i] = u; b[i] = v;
        g[u][v] = g[v][u] = true;
    }

    int ans = 0;
    rep(i, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        rep(j, n) seen[j] = false;
        dfs(0);
        bool bridge = false;
        rep(j, n) if (!seen[j]) bridge = true;
        if (bridge) ans++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s,t;
    int a,b;
    string u;
    cin>>s>>t>>a>>b>>u;
    if(s == u)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
using t = tuple<int,int,int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n = 105;
int m = 1005;
map<P,int> mp;
vector<vector<P>> graph(n,vector<P>());
vector<bool> used(m,false);

int id(int i,int j){
    if(i > j) swap(i,j);
    return mp[P(i,j)];
}

void Dijkstra(int start){
    vector<bool> seen(n,false);
    vector<int> shoretest(n,0);
    priority_queue<t,vector<t>,greater<t>> pq;
    pq.push(t(0,start,-1));

    while(!pq.empty()){
        int dist = get<0>(pq.top());
        int v = get<1>(pq.top());
        int before = get<2>(pq.top());
        pq.pop();
        
        if(seen[v] && dist == shoretest[v]) used[id(before,v)] = true;
        if(seen[v]) continue;

        if(before!=-1){
            used[id(before,v)] = true;
        }
        shoretest[v] = dist;
        seen[v] = true;

        for(P next:graph[v]){
            int next_node = next.second;
            int next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(t(next_cost + dist,next_node,v));
        }
    }

    return ;
}

int main(){
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a;--b;
        graph[a].push_back(P(c,b));
        graph[b].push_back(P(c,a));
        if(a > b) swap(a,b);
        mp[P(a,b)] = i;
    }

    rep(i,n) Dijkstra(i);

    int ans = 0;
    rep(i,m){
        ans += !used[i];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
def resolve():
    H, N = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for i in range(N)]
    maxa = max([ab[0] for ab in AB])
    dp = [-1 for _ in range(H+maxa+1)]
    dp[0] = 0
    for i in range(H+1):
        if dp[i] == -1:
            continue
        for a, b in AB:
            dp[i+a] = min(dp[i+a], dp[i]+b) if dp[i+a] != -1 else dp[i]+b
    print(min(filter(lambda x: x != -1, dp[H:])))

    
    
if __name__ == "__main__":
    resolve()


Measured memory_bytes: 74012
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt(), b = scan.nextInt();
		ArrayList<String> ABC = new ArrayList<String>();
		String output = "";
		for (int i = 0;  i < a; i++ )
		{
			ABC.add(scan.next());
		}
		
		for (int i = 0; i < a;i++)
		{
			String small = ABC.get(0);
			for (int x = 1; x < ABC.size();x++)
			{
				if (small.compareTo(ABC.get(x)) > 0) small = ABC.get(x);
			}
			output+=small;
			ABC.remove(small);
		}
		System.out.println(output);
	}
}

Measured memory_bytes: 24276
let () =
  let w,a,b = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in

  let t = if a < b then
      b-a-w
    else if a > b then
      a-b-w
    else 0
  in
  Printf.printf "%d\n" @@
    if t <= 0 then 0 else t


Measured memory_bytes: 384