akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define long long long

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> X;
  for(int i=0; i<N; i++){
    int x; cin >> x;
    X.push_back(x);
  }
  vector<long> dist(N-K+1, 0);
  for(int i=0; i<K-1; i++){
    dist[0]+=X[i+1]-X[i];
  }
  if(abs(X[0])>abs(X[K-1])){
    dist[0]+=abs(X[K-1]);
  }else{
    dist[0]+=abs(X[0]);
  }
  for(int i=K; i<N; i++){
    dist[i-K+1]=dist[i-K]-(X[i-K+1]-X[i-K])+(X[i]-X[i-1]);
    if(abs(X[i-K])>abs(X[i-1])){
      dist[i-K+1]-=abs(X[i-1]);
    }else{
      dist[i-K+1]-=abs(X[i-K]);
    }
    if(abs(X[i-K+1])>abs(X[i])){
      dist[i-K+1]+=abs(X[i]);
    }else{
      dist[i-K+1]+=abs(X[i-K+1]);
    }
  }
  sort(dist.begin(), dist.end());
  cout << dist[0] << endl;
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, d, x;
    cin >> n >> d >> x;
    int ans=x;
    REP(i,n) {
        int a;
        cin >> a;
        ans++;
        ans+=(d-1)/a;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(a: int, b: int, h: int):
    ret = (b + a) * h / 2
    print(int(ret))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    h = int(next(tokens))  # type: int
    solve(a, b, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int n, k, ans=0;
    cin >> n >> k;
    vector<int> a(n), num;
    rep(i, n)cin >> a.at(i);
    sort(all(a));
    int cnt=1;
    REP(i, n-1){
        if(a.at(i) != a.at(i-1)){
            num.push_back(cnt);
            cnt=1;
        }
        else cnt++;
    }
    num.push_back(cnt);
    sort(all(num));
    int size = num.size();
    for(int i = 0; i < size-k; i++){
        ans += num.at(i);
    }
    cout << ans;
}


Measured memory_bytes: 2168
<?php
$s = trim(fgets(STDIN));
$s1 = $s[0].$s[1];
$s2 = $s[2].$s[3];
if($s1 >= 1 && $s1 <= 12 && $s2 >= 1 && $s2 <= 12 ){
    echo 'AMBIGUOUS';
}elseif($s1 >= 1 && $s1 <= 12){
    echo 'MMYY';
}elseif($s2 >= 1 && $s2 <= 12){
    echo 'YYMM';
}else{
    echo "NA";
}


Measured memory_bytes: 4728
import javax.swing.text.Position;
import java.util.Scanner;

public class Main {

    static Scanner scan = new Scanner(System.in);
    public static void main(String[] args) {
        int N, M;
        boolean[][] field = new boolean[21][21];
        while((N=scan.nextInt()) != 0){
            int positionX = 10;
            int positionY = 10;
            int count = 0;

            for(int i=0; i< 21; i++){
                for(int j=0; j<21; j++){
                    field[i][j] = false;
                }
            }

            for(int i=0; i<N; i++){
                int x = scan.nextInt();
                int y = scan.nextInt();
                field[y][x] = true;
            }

            M = scan.nextInt();

            for(int i=0; i<M; i++){
                String d = scan.next();
                int j = scan.nextInt();

                for(int k=0; k<j; k++) {
                    switch(d.charAt(0)){
                        case 'N':
                            positionY++;
                            break;
                        case 'E':
                            positionX++;
                            break;
                        case 'W':
                            positionX--;
                            break;
                        case 'S':
                            positionY--;
                            break;
                        default:
                            System.exit(-1);
                    }

                    if (field[positionY][positionX] == true) {
                        count += 1;
                        field[positionY][positionX] = false;
                    }
                }
            }

            if(count == N){
                System.out.println("Yes");
            } else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 32268
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1e9+7;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,ans;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
int main(){
	n=read();
	ans=qpow(10,n);
	ans=(ans-(qpow(9,n)<<1)%mod+mod)%mod;
	ans=(ans+qpow(8,n))%mod;
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 3796
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int N; cin >> N;
	map<vector<int>, int> cnt;
	while (N--) {
		string s; cin >> s;
		vector<int> v('z' - 'a' + 1, 0);
		for (auto c : s)
			++v[c - 'a'];
		++cnt[v];
	}
	ll res = 0;
	for (auto& e : cnt)
		res += (ll)e.second * (e.second - 1) / 2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 18944
# -*- coding: utf-8 -*-
S = input()
len_S = len(S)
#Rは右方向に最も近いL,Lは左方向に最も近いRを探す
S_asshuku = []
min_lens = []
ret_list = [0] * len_S
cnt = 1
for i in range(1,len_S):
    if S[i]==S[i-1]:
        cnt+=1
    else:
        S_asshuku.append(cnt)
        cnt = 1
S_asshuku.append(cnt)
for i,v in enumerate(S_asshuku):
    if i%2==0:#Rの場合
        min_lens += list(range(v,0,-1))
    else:#Lの場合
        min_lens += list(range(1,v+1))
for i,(s,ml) in enumerate(zip(S,min_lens)):
    if s=="R":
        ret_list[i+ml-ml%2]+=1
    else:
        ret_list[i-ml+ml%2]+=1
print(" ".join(list(map(str,ret_list))))


Measured memory_bytes: 14692
#include <iostream>
#include <string>
using namespace std;
 
long long MOD=1000000007;
int n;
int f[500][500];
int cost[500];
 
int jc(int c){
	return 2;
}
 
int ic(int c){
	for(int i = 0;i < n;i++){
		if(f[i][c] == 1) return 1;
	}
	return 2;
}
 
void cc(){
	for(int i = 0;i < n;i++){
		cost[i] = ic(i);
	}
}
 
int main() {
	// your code goes here
	cin >> n;
	string str;
	bool ng = false;
	for(int i = 0;i < n;i++){
		cin >> str;
		for(int j = 0;j < n;j++){
			if(str[j] == '#'){
				f[i][j] = 1;
				ng = true;
			}
			else{
				f[i][j] = 0;
			}
		}
	}
	if(ng == false){
		cout << -1 << endl;
		return 0;
	}
	cc();
	int is[500];
	int imax = 0;
	int imin = n;
	for(int i = 0;i < n;i++){
		is[i] = 0;
		int fb = 0;
		for(int j = 0;j < n;j++){
			if(f[i][j] != 1){
				is[i] += 1;
				if(cost[i] == 2) fb = 1;
			}
		}
		is[i] += fb;
		if(imax < is[i]){
			imax = is[i];
		}
		if(imin > is[i]){
			imin = is[i];
		}
	}
	int js;
	int a = 0;
	for(int i = 0;i < n;i++){
		js = 0;
		for(int j = 0;j < n;j++){
			js += f[j][i];
		}
		if(js != n){
			a++;
		}
	}
	cout << a+imin << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	int ans=0;
	for(int i=1;i+1<n;i++) {
		vector<int> v;
		for(int j=-1;j<=1;j++) v.push_back(p[i+j]);
		sort(v.begin(),v.end());
		if(v[1] == p[i]) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
s=input()
k=int(input())
fl=0
t=0
ans='1'
for i in range(len(s)):
  if s[i]=='1' and fl==0:
    t+=1
  else:
    if fl==0:
      ans=s[i]
      fl=1
if t>=k:
  ans='1'
print(ans)


Measured memory_bytes: 38256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(s) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

void calc() {
	int n; cin >> n;
	using T = tuple<int, int, int>;
	vector<T> v(n);
	rep(i, n) {
		int x, y; cin >> x >> y;
		v[i] = T(x, y, i);
	}
	sort(all(v));
	auto u = v;
	sort(all(u), [](T p1, T p2) {
		return get<1>(p1) < get<1>(p2);
	});

	vector<T> edge;
	auto& tmp = v;
	rep(i, n - 1) {
		int l = get<0>(tmp[i + 1]) - get<0>(tmp[i]);
		int a = get<2>(tmp[i + 1]), b = get<2>(tmp[i]);
		edge.push_back(T(l, a, b));
	}
	tmp = u;
	rep(i, n - 1) {
		int l = get<1>(tmp[i + 1]) - get<1>(tmp[i]);
		int a = get<2>(tmp[i + 1]), b = get<2>(tmp[i]);
		edge.push_back(T(l, a, b));
	}

	sort(all(edge));
	UnionFind uf(n);
	int ans = 0;
	for (T t : edge) {
		int l, a, b;
		tie(l, a, b) = t;
		if (!uf.findSet(a, b)) {
			uf.unionSet(a, b);
			ans += l;
		}
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;


int main()
{		
		
	  ll a,b;
	  cin>>a>>b;
	  ll ans=((b-1+(a-2))/(a-1));
	  cout<<ans;


	   


}
    
 
    
    


Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]

m,a,r,c,h=0,0,0,0,0
for s_i in s:
    if s_i[0] == "M":
        m+=1
    if s_i[0] == "A":
        a+=1
    if s_i[0] == "R":
        r+=1
    if s_i[0] == "C":
        c+=1
    if s_i[0] == "H":
        h+=1

lst=[m,a,r,c,h]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=lst[i]*lst[j]*lst[k]

print(ans)

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

using namespace std;

int main() {
  int n,x;
  cin>>n>>x;
  vector<int>d;
  vector<int>l;
  d.push_back(0);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    l.push_back(k);
  }
  for(int i=0;i<n;i++){
    d.push_back(d[i]+l[i]);
  }
  int ans = 0;
  for(int i=0;i<d.size();i++){
    if(d[i]<=x){
        ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    long long int n, num=1, k, cnt=0;
    int o=0;
    cin >> n;

    for(int i=0; i<n; i++)
	{
        cin >> k;
        if(k==num)
            num++;
        else
            cnt++;
        if(k == 1)
            o=1;
    }
    
	if(o)
        cout << cnt;    
    else
        cout << -1;
    return 0;
}


Measured memory_bytes: 256
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]  #[0, 1, 2, 3, 4, 5]
        self.work = [i for i in range(6)]

    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def equal(self, dice):  # 自分と引数のサイコロが同一か判定
        directions = "EEEENEEEENEEEENEEEEWSEEEESSEEEE"  # サイコロの向きの全通りを試すための転がす命令（余分な転がしも含む）
        for d in directions:
            self.roll(d)
            for i in range(6):
                if self.number[i] != dice.number[i]:
                    break
                if i == 5:
                    return True
        return False

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice()
dice1.setNumber(num1[0], num1[1], num1[2], num1[3], num1[4], num1[5])
dice2 = Dice()
dice2.setNumber(num2[0], num2[1], num2[2], num2[3], num2[4], num2[5])
if dice1.equal(dice2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5620
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      k[i] = scanner.nextInt();
      for (int j = 0; j < k[i]; j++) {
        a[i][j] = scanner.nextInt();
      }
    }
    boolean[][] map = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        map[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < k[i]; j++) {
        map[i][a[i][j] - 1] = true;
      }
    }
    int count = 0;
    boolean isTrue;
    for (int i = 0; i < m; i++) {
      isTrue = true;
      for (int j = 0; j < n; j++) {
        if (!map[j][i]) {
          isTrue = false;
        }
      }
      if (isTrue) {
        count++;
      }
    }
    System.out.println(count);
  }

}


Measured memory_bytes: 22996
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int N, M, a[364364];
long long int r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(int &x){int k;x=0;for(;;){k=gc();if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}}

int main(){
    read(N);
    M = N + (N << 1);
    for(int i = 0; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<int>());
    N <<= 1;
    ++N;
    for(int i = 1; i ^ N; i += 2){
        r += a[i];
    }
    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) { // xとyの木を併合
      if(x>y) swap(x,y);
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
      if(rx>ry) swap(rx, ry);
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  vector<int> aaa(N, 0);
  
  rep(i, M){
  int a, b;
    cin >> a >> b;
    tree.unite(a-1, b-1);
  }
  
  rep(i, N){
  aaa[tree.root(i)]++;
  }
  int ans=0;
  rep(i, N){
  ans=max(ans, aaa[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4824
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        List<Integer> digits = new ArrayList<>();
        while (S > 0) {
            digits.add(S%10);
            S /= 10;
        }

        int answer = (int) digits.stream()
                .filter(digit -> digit == 1)
                .count();

        System.out.println(answer);
    }
}

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

int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int k = 1;
    rep(i,N){
        if(a[i] == k) k++;
    }
    if(k == 1) cout << -1 << endl;
    else cout << N-(k-1) << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 1;
        int x = 1;
        int y = 1;
        
        while(true){
            x = sc.nextInt();
            y = sc.nextInt();
            
            if(x <= y && (x != 0 || y != 0)){
                System.out.println(x + " " + y);
            }else if(x > y && (x != 0 || y != 0)){
                System.out.println(y + " " + x);
            }else{
                break;
            }
        }
    }
}


Measured memory_bytes: 35364
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;
    vi l(n); rep(i,n) cin >> l[i];
    sort(all(l), greater<int>());
    int ans = 0;
    rep(i,k) {
        ans += l[i];
    }
    ct(ans);
}



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

int main(){
  
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  
  set< string > ss;
  
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){
      string tmp = s.substr(i, j);
      ss.insert(tmp);
    }
  }
  
  auto itr = ss.begin();
  for(int i = 0; i < k - 1; i++) itr++;
  cout << *itr << endl;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 3000;

int N;
ll a[MAX_N];
ll memo[MAX_N][MAX_N];

ll memoize(int left, int right){
	int itv = right - left + 1;
	if(left == right){
		if(N % 2 == 1) return memo[left][right] = a[left];
		else return memo[left][right] = -a[left];
	}
	if(memo[left][right] != -1) return memo[left][right];
	if((N - itv) % 2 == 0){
		return memo[left][right] = max(memoize(left + 1, right) + a[left], memoize(left, right - 1) + a[right]);
	}else{
		return memo[left][right] = min(memoize(left + 1, right) - a[left], memoize(left, right - 1) - a[right]);
	}
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld", &a[i]);
	fill(memo[0], memo[N], -1);
	printf("%lld\n", memoize(0, N - 1));
	return 0;
}


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

using namespace std;

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

  int maxFactor = 0;
  for (int a = 1; a * a <= M; a++) {
    if (M % a != 0) continue;
    int b = M / a;

    if (a >= N) {
      maxFactor = max(maxFactor, b);
    }
    if (b >= N) {
      maxFactor = max(maxFactor, a);
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
from numba import njit
import numpy as np


def main(S, T):
    if len(T)-len(S) != 1:
        print("No")
        return
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
            if count > 0:
                print("No")
                return
    print("Yes")


S = input()
T = input()
main(S, T)


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

int main()
{
  int sum;
  int N, K;
  cin >> N >> K;
  
  sum = 1;
  for (int i = 0; i < N; i++)
  {
    if (sum * 2 < sum + K)
      sum *= 2;
    else
      sum += K;
  }
  cout << sum << endl;
}

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

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

l1=make_divisors(N)
ans=len(make_divisors(N-1))-1

for i in l1:
    m=N
    while m%i==0 and m!=1 and m!=0 and i!=1:
        m//=i
    if m%i==1:
        ans+=1

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{double t,x;
 cin >> t >> x;
 
 cout << t/x << endl;
 
    
    return 0;
}

Measured memory_bytes: 256
//For fast competitive programming

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

//DATA_TYPES
typedef long long ll; 
typedef vector<int> vi;
typedef pair<int, int> ii; 
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f; //Infinity

//INITIALISING
//memset(arr, 0, sizeof arr);
//vi v(N, 0);

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(NULL);
	
	//write your code here
	int n;
	string str;
	cin>>n;
	//getline (cin,str); 
	//cout<<str;
    cin>>str;
    //cout<<" "<<str;
    if(str.size()<=n)
    {
        cout<<str;
        return 0;
        
    }
    //cout<<" "<<str.size();
    str.resize(n);
    
    cout<<str<<"...";
    
    
	return 0;
}

Measured memory_bytes: 3652
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


constexpr double INF = 1e18;
int main() {
	int N,M;
	cin >> N >> M;
	vector<double> a(N);
	cin >> a;
	vector<vector<double>> dp(N + 1, vector<double>(M + 1, -INF));
	dp[0][0] = 0;
	for (int i : range(N + 1)) {
		for(int c:range(M)){
			double hsum = 0;
			double len = 0;
			for (int j : range(i + 1, N + 1)) {
				hsum += a[j - 1];
				len += 1.0;
				chmax(dp[j][c + 1], dp[i][c] + hsum / len);
			}
		}
	}
	cout << fixed;
	cout << setprecision(10);
	double ret = -INF;
	for (int i : range(M + 1))chmax(ret, dp.back()[i]);
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 5084
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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


int main() {
	ll H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) {
		cout << 1 << endl;
		return 0;
	}

	cout << (H * W + 1LL) / 2LL << endl;
	
	return 0;
}


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

#define STSIZE 100

int top = 0;
int a[STSIZE];

void push(int);
int pop(void);

int main()
{
  char s[100];
  int i,j,num,x;
  int k;

  
  while(scanf("%s",s)!=EOF){
    if(s[0] == '+'){
      i = pop();
      j = pop();
      num = i + j;
      push(num);
    }
    else if(s[0] == '-'){
      i = pop();
      j = pop();
      num = j - i;
      push(num);
    }
    else if(s[0] == '*'){
      i = pop();
      j = pop();
      num = i * j;
      push(num);
    }
    else {
      x = atoi(s);
      push(x);
    }
   
   
  }

  k = pop();
    printf("%d\n",k);
   
  
  return 0;
}

void push(int x)
{
  top++;
  a[top] = x;
}

int pop(void)
{
  top--;
  return a[top+1];
}



Measured memory_bytes: 2100
#include<stdio.h>
#define M 1000000000
int l;
void f(int n,int *a){//kakunou
  int i;
  for(i=0;i<l;n/=3)a[i++]=n%3;
}
int g(int *a){
  int n=0,i;
  for(i=l;i;i--)n=n*3+a[i-1];
return n;
}
void prih(int *h,int r){
  int i,j=0;
  for(i=0;i<=r;i++){
    if(i==1<<j){
      printf("\n");
      j++;
    }
    printf("%d ",h[i]);
  }printf("\n");
  }//*/
int main(){
  char s[20];
  int i,j,k,mi,n,r,a[12],c[60000],h[1000000];
  while(scanf("%s",s),s[0]-'0'){
    for(h[i=0]=-M;i<60000;i++)c[i]=M;
    for(i=r=1;i<1000000;i++)h[i]=M;
    for(l=n=0;s[l];l++){
      if(s[l]=='r')n=n*3+0;
      if(s[l]=='g')n=n*3+1;
      if(s[l]=='b')n=n*3+2;
    }
    c[mi=n]=0;
    for(i=n=0;i<l;i++)n=n*3+1;//printf("%d\n",n);
    if(mi==0||mi==n||mi==n*2){
      printf("0\n");
      continue;
      }//*/
    //h[r=1]=c[n]*60000+n;
    while(1){
      for(i=1;i<l;i++){//printf("%d\n",mi);
    f(mi,a);
    //for(j=0;j<l;j++)printf("%d",a[j]);printf("\n");
    a[i-1]=a[i]=(6-a[i-1]-a[i])%3;
    //for(j=0;j<l;j++)printf("%d",a[j]);printf("\n");
    j=g(a);//printf("%d\n",j);
    //if(j==0||j==n||j==n*2)break;
    if(c[j]>c[mi]+1){
      c[j]=c[mi]+1;//printf("%d\n",c[j]);
      k=c[j]*60000+j;//printf("k%d\n",k);
      for(j=r++;h[j/2]>k;j/=2)h[j]=h[j/2];
      h[j]=k;//printf("%d\n",j);
    }
      }//printf("\n");prih(h,r);printf("%d\n",r);
      //if(l-i)break;
      mi=h[i=1]%60000;//printf("%d\n",mi);
      //if(mi==0||mi==n||mi==n*2)break;
      if(r==1)break;
      k=h[--r];
      for(h[r]=M;k>h[i];i=j){
    h[i]=h[j=i*2];
    if(h[i]>h[j+1])h[i]=h[j=j+1];
      }//printf("mi%d\n",mi);
      //if(i==1)break;
      if(r-1)h[i/2]=k;
    }//printf("%d %d\n",h[0],h[1]);
    if(c[0]>c[n  ])c[0]=c[n  ];
    if(c[0]>c[n*2])c[0]=c[n*2];
    if(c[0]-M)printf("%d\n",c[0]);
    else      printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 4688
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}

fn r10(a: i64) -> i64 {
    ((a-1)/10+1)*10
}
fn main() {

    let l1 = read_line();
    let l2 = read_line();
    let l3 = read_line();
    let l4 = read_line();
    let l5 = read_line();
    
    let a: i64 = to_i(&l1);
    let b: i64 = to_i(&l2);
    let c: i64 = to_i(&l3);
    let d: i64 = to_i(&l4);
    let e: i64 = to_i(&l5);
/*
    println!("{} {} {}", 1, r10(1), 10 );
    println!("{} {} {}", 9, r10(9), 10 );
    println!("{} {} {}", 10, r10(10), 10 );
    println!("{} {} {}", 11, r10(11), 20 );
*/
    let mut v = Vec::new();
    v.push(a);
    v.push(b);
    v.push(c);
    v.push(d);
    v.push(e);
    let n = v.len();

    let mut maxIndex = 0;
    let mut maxValue = 0;
    for i in 0..n {
        let x = v[i];
        let r = r10(x);
        let diff = r-x;
        //println!("{} {}", i, x);
        if i==0 {
            maxValue = diff;
        }
        if diff > maxValue {
            maxValue = diff;
            maxIndex = i;
        }
    }

    //println!("{} {}", maxIndex, maxValue);

    let mut sum = 0;
    for i in 0..n {
        let x = v[i];
        let r = r10(x);
        if i==maxIndex {
            sum += x;
        } else {
            sum += r;
        }
    }

    print!("{}", sum);
    /*

    let mut fail = false;
    for i in 0..n {
        for j in i+1..n {
            let l = v[j]-v[i];
            // println!("{} {} {}",i,j,l);
            if l>k {
                fail = true;
                break;
            }
        }
    }
    
    if fail {
        print!(":(");
    } else {
        print!("Yay!");
    }
    */


}   

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  string s;
  cin>>s;
  string t="";
  int n=s.size();
  rep(i,n){
    //cout<<t<<endl;
    if(s[i]=='B'){
      if(t!="")t.erase(prev(t.end()));
    }
    else if(s[i]=='0')t+="0";
    else t+="1";
  }
  cout<<t;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <cmath>
#include <math.h> 

int main() {
  string s;
  cin >> s;
  int l = s.length();
  int p = 0;
  for(int i=0;i<int(l/2);i++){
    if(s[i] != s[l - 1 - i]){
      p++;
    }
  }
  cout << p;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int X = sc.nextInt();
    
    if (X < 30) {
      System.out.println("No");
    }else if (X >= 30) {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 35612
N = int(input())
A = list(map(int, input().split()))

# 操作回数
counter = 0

# 操作が行えなくなるまで操作を行う
while True:
    # // 操作が行えるかどうかを判定する
    can_do = True
    for i in range(N):
        if A[i] % 2 == 1:
            can_do = False

    # 操作を行えないならば、ループを打ち切る
    if not can_do:
        break

    # 操作を行えるならば、操作を行う
    for i in range(N):
        A[i] //= 2

    # 操作回数をカウントする
    counter += 1

print(counter)

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

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}

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

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

    for(int i = 0; i < n; i++){
        map<pair<int,int>,int> m;
        for(int j = 0; j < n; j++){
            if(i == j)  continue;
            int diffx = x[j]-x[i], diffy = y[j]-y[i];
            if(diffx < 0)   diffx *= -1, diffy *= -1;
            int g = gcd(abs(diffx), abs(diffy));
            diffx /= g, diffy /= g;
            if(++m[{diffx,diffy}] >= k-1){
                cout << 1 << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 3336
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,ans=700;
	string s;
	ll count[3] = {0,0,0};

	cin >> s;

	forll(i, 0, s.size())
	{
		if (s[i] == 'o')
			ans += 100;
	}
	
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
const int INF = 1000000007;

int main(){
   int n, x, y;
   cin >> n >> x >> y;
   x--; y--;
   vector<int> ans(n);
   for(int sv = 0; sv < n; sv++){ //すべての頂点から試す
      vector<int> dist(n, INF);
      queue<int> q;
      auto push = [&](int v, int d){ //vにdで行ける
         if(dist[v] != INF) return;
         dist[v] = d;
         q.push(v); //あるノードへの距離とキュー更新
      };

      //ここからbfs
      push(sv, 0);
      while(!q.empty()){
         int v = q.front(); q.pop();
         int d = dist[v];
         if(v-1 >= 0) push(v-1, d+1);
         if(v+1 < n) push(v+1, d+1);
         if(v==x) push(y, d+1);
         if(v==y) push(x, d+1);
      }
      for(int i = 0; i < n; i++) ans[dist[i]]++;
   }
   for(int i = 0; i < n; i++) ans[i] /= 2; //(i,j)と(j,i)を別にしているので
   for(int i = 1; i < n; i++){
      cout << ans[i] << endl;
   }
   return 0;
}
 

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

const int mod = 1000*1000*1000+7;
const int MAXN = 200*1000+5;

vector<int> g[MAXN];
int fact[MAXN], fact_inv[MAXN], ans[MAXN], sz[MAXN], n;

int mul(int a, int b) { 
	return 1LL * a * b % mod; 
}

int mpow(int a, int k) {
	if(k == 0) return 1;
	int x = mpow(a, k/2);
	x = mul(x, x);
	if(k % 2 == 1) x = mul(x, a);
	return x;
}

void dfs_pre(int u, int p = -1) {
	int& res = ans[u] = 1;
	sz[u] = 1;
	for(int v : g[u]) {
		if(v != p) {
			dfs_pre(v, u);
			res = mul(res, ans[v]);
			res = mul(res, fact_inv[sz[v]]);
			sz[u] += sz[v];
		}
	}
	res = mul(res, fact[sz[u]-1]);
}

void dfs(int u, int p = -1) {
	int& res = ans[u] = fact[n-1];
	for(int v : g[u]) {
		res = mul(res, ans[v]);
		res = mul(res, fact_inv[sz[v]]);
	}
	
	for(int v : g[u]) {
		if(v != p) {
			int tmp1 = ans[v], tmp2 = sz[u];
			res = mul(res, mpow(tmp1, mod-2));
			res = mul(res, fact_inv[n-1]);
			sz[u] = n - sz[v];
			res = mul(res, fact[sz[u]-1]);
			res = mul(res, fact[sz[v]]);
			dfs(v, u);
			res = mul(res, fact_inv[sz[v]]);
			res = mul(res, fact_inv[sz[u]-1]);
			sz[u] = tmp2;
			res = mul(res, fact[n-1]);
			res = mul(res, tmp1);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fact[0] = fact_inv[0] = 1;
	for(int i = 1; i < MAXN; i++) {
		fact[i] = mul(fact[i-1], i);
		fact_inv[i] = mpow(fact[i], mod-2);
	}
	
	cin >> n;
	for(int i = 0; i < n-1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs_pre(0);
	dfs(0);
	for(int i = 0; i < n; i++) {
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 19060
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 
#define pll pair<ll,ll>

ll pre[402];
ll dp[402][402];

ll ans(int l,int r)
{
   if(l==r)return 0;
   if(dp[l][r]!=-1)return dp[l][r];
   ll mini = (ll)(1e18);
   f(i,l,r)
   {
      mini = min(mini,ans(l,i)+ ans(i+1,r));
   }
   dp[l][r] = mini + pre[r]-pre[l-1];
   // cout<<l<<" "<<r<<" "<<dp[l][r]<<"\n";
   return dp[l][r];
}

void solve()
{
   ll n;
   cin>>n;
   ll a[n+1];
   f(i,1,n+1)cin>>a[i];
   pre[0]=0;
   f(i,1,n+1)pre[i] = pre[i-1] + a[i];
   f(i,1,n+1)
   {
      f(j,1,n+1) dp[i][j]=-1;
   }
   cout<<ans(1,n);

}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, k; cin >> N >> k;
	ll ans = 0;
	for (int i = 1; i <= N - 2;) {
		if (i + 110 < N - 2) {
			ans += 50;
			i += 110;
			continue;
		}
		for (int j = 1; j <= 5; j++)
			if (((ll)i * 7 + j + 1) * 9 % 11 == k)
				ans++;
		i++;
	}
	cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> a(n);
  rep(i, n){
    cin >> a.at(i);
  }
  double b=0;
  rep(i, n){
    b += 1/a.at(i);
  }
  cout << 1/b << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]

use std::cmp::{max, min};

macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};
  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };
  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };
  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };
  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };
  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: i32,
    x: [i32; n],
  }
  let mut ans = 1_000_000_000;
  for p in 1..101 {
    let mut sum = 0;
    for x in x.iter() {
      sum += (x - p) * (x - p);
    }
    ans = min(ans, sum);
  }
  println!("{}", ans);
}


Measured memory_bytes: 2132
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

unordered_map<ll, ll> mp;
ll n;
vector<ll> a;

void solve() {
    ll summ = 0;
    ll d[n + 1];
    rep(i, n + 1) {
        d[i] = abs(a[i + 1] - a[i]);
        summ += d[i];
    }
    repone(i, n) {
        if ((a[i + 1] - a[i]) * (a[i - 1] - a[i]) > 0) {
            cout << summ - 2 * min(d[i], d[i - 1]) << endl;
        } else {
            cout << summ << endl;
        }
    }
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = unordered_map<ll, ll>();
#pragma clang diagnostic pop
#endif
        cin >> n;
        a.resize(n + 2);
        a[0] = 0;
        repone(i, n)cin >> a[i];
        a[n + 1] = 0;

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = ReadInt();

            var fifteen = X / 500;
            var five = (X - fifteen * 500) / 5;

            WriteLine(fifteen * 1000 + five * 5);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

const int MAX_HW = 101010;
const int INF = 1001001001;

ll maxY[MAX_HW], maxX[MAX_HW];

int main() {
    ll w, h, n;
    cin >> w >> h >> n;
    ll x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        maxY[x] = max(maxY[x], y);
        maxX[y] = max(maxX[y], x);
    }
    for (int i = w - 2; i >= 0; i--) {
        maxY[i] = max(maxY[i], maxY[i + 1]);
    }
    for (int i = h - 2; i >= 0; i--) {
        maxX[i] = max(maxX[i], maxX[i + 1]);
    }
    ll ans = INF;
    for (ll y = 0; y < h; y++) {
        ans = min(ans, y + maxX[y + 1]);
    }
    for (ll x = 0; x < w; x++) {
        ans = min(ans, x + maxY[x + 1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4660
def solve(n, a):
    prod = 1
    for a_i in a:
        prod *= a_i
    dev = 0
    for a_i in a:
        dev += prod / a_i
    return prod / dev
    

if __name__ == "__main__":
    n = int(input().strip())
    a = list(map(int, input().strip().split(" ")))

    print(solve(n, a))

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		int cnt = 0;
		for (int a = 0; a < 10; ++a) {
			for (int b = 0; b < 10; ++b) {
				for (int c = 0; c < 10; ++c) {
					for (int d = 0; d < 10; ++d) {
						if (a + b + c + d == n) {
							cnt++;
						}
					}
				}
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] p = new int[n + 1];
		int[][] m = new int[n + 1][n + 1];

		for (int i = 0; i < n; i++) {
			p[i] = scan.nextInt();
			p[i + 1] = scan.nextInt();
		}
		

		// (M1)(M2M3M4M5) l=2
		// (M1M2)(M3M4M5) l=3
		for (int l = 2; l <= n; l++) {
			for (int i = 1; i <= n - l + 1; i++) {
				int j = i + l - 1;
				m[i][j] = (1 << 21);
				for (int k = i; k <= j - 1; k++) {
					m[i][j] = Math.min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
				}
			}
		}
		
		System.out.println(m[1][n]);
		scan.close();
	}
}

Measured memory_bytes: 26576
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end());

const int MOD = 1000000007;
const int INF = INT_MAX;
const double PI = 3.14159265358979323846;



int main()
{

    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i=0; i < n; i++){
        cin >> s[i];
    }

    vsort(s);


    for (int i=0; i < n; i++){
        cout << s[i];
    }
    cout << endl;


    



    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int n,m,sum[305],ans=(1<<30);
queue<int> q[305];
bool vis[305];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	q[i].push(read());
	for(int i=1;i<=m;i++)
	{
		memset(sum,0,sizeof(sum));
		for(int j=1;j<=n;j++)
		{
			while(!q[j].empty() && vis[q[j].front()]) q[j].pop();
			sum[q[j].front()]++;
		}
		int maxa=0,pos;
		for(int j=1;j<=m;j++)
		if(sum[j]>maxa)
		{
			maxa=sum[j];
			pos=j;
		}
		vis[pos]=1;
		if(maxa) ans=min(ans,maxa);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 105
int n,m,a[N],cnt,len;
int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,m) scanf("%d",&a[i]),cnt+=(a[i]&1);
	if (m==1){
		if (n==1) printf("1\n1\n1");else printf("%d\n2\n%d 1\n",n,n-1);
		return 0;
	}
	if (cnt>2) return puts("Impossible"),0;
	rep (i,1,m)
		if (a[i]&1)
			if (!(a[1]&1)) swap(a[1],a[i]);else swap(a[m],a[i]);
	rep (i,1,m) printf("%d ",a[i]);puts("");
	len=m;if (a[m]==1) len--;
	printf("%d\n",len);
	rep (i,1,m){
		if (i==1) printf("%d ",a[1]+1);
		else if (i==m){if (a[m]>1) printf("%d ",a[m]-1);}
		else printf("%d ",a[i]);
	}
	return 0;
}

Measured memory_bytes: 256