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

int main() {
  using ll =long long ;
  ll a;
  cin>>a;
  ll b=0;
  ll c=0;
  vector<ll>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
    vec.at(i)=vec.at(i)%1000000007;
    b+=vec.at(i);
    b=b%1000000007;
    c+=vec.at(i)*vec.at(i);
    c=c%1000000007;
  }
  ll e=b*b-c;
  for(ll i=0;e<0;i++){
    e+=1000000007;
  }
  if(e%2!=0){
    e+=1000000007;
  }
  ll f=e/2;
  ll g=f%1000000007;
  
  
  cout<<g<<endl;
    
    
}

Measured memory_bytes: 4776
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	int L=N%2?N:N+1;
	
	vector<pair<int,int>> P;
	REP(i,N){
		for(int j=i+1;j<N;j++){
			if(j+1+i+1==L) continue;
			P.emplace_back(i+1,j+1);
		}
	}
	out(P.size());
	for(auto& x:P) out(x.first,x.second);
	return 0;
}


Measured memory_bytes: 384
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

vector<int> v[100001];
bool visited[100001];
int dis[100001];
void dfs(int u)
{
    visited[u]=true;
    for(int i=0;i<v[u].size();++i)
    {

        if(!visited[v[u][i]])
            dfs(v[u][i]);
        dis[u]=max(dis[u],dis[v[u][i]]+1);
        
    }
}
void find(int n)
{
    for(int i=1;i<=n;++i)
    {
        if(!visited[i])
        {

            dfs(i);
        }
    }
  
}


int32_t main()
{
    IOS
    
        
 
     int n,m;
     cin>>n>>m;
    
    for(int i=0;i<m;++i)
    {
        int p,q;
        cin>>p>>q;
        v[p].push_back(q);
    }
    memset(visited,false,sizeof(visited));
    memset(dis,0,sizeof(dis));
    find(n);
    int ans=0;
    for(int i=1;i<=n;++i)
        ans=max(ans,dis[i]);
    
     cout<<ans;
    

    
}


Measured memory_bytes: 8320
#include<stdio.h>
#include<string.h>
int M = 1000003;
int A[1000003];
int getChar(char s)
{
    if(s == 'A')
        return 1;
    else if(s == 'C')
        return 2;
    else if(s == 'G')
        return 3;
    else if(s == 'T')
        return 4;
    else
        return 0;
}
long long getKey(char s[])
{
    long long nums = 0;
    for(int i=0; i < strlen(s); i++)
        nums = 5 * nums + getChar(s[i]);

    return nums;
}

int h1(long long key)
{
    return key % M;
}
int h2(long long key)
{
    return 1 + key % (M - 1);
}

void insert(int A[], char s[])
{
    long long key = getKey(s);
    int i = 0;
    int h = (h1(key) + i * h2(key)) % M;
    while(A[h] != -1)
    {
        i++;
        h = (h1(key) + i * h2(key)) % M;
    }
    A[h] = key;
}

bool find(int A[], char s[])
{
    long long key = getKey(s);
    int i = 0;
    int h = (h1(key) + i*h2(key)) % M;
    while(true)
    {
        h = (h1(key) + i*h2(key)) % M;
        if(A[h] == key)
            return true;
        else if(A[h] == -1 || i >= M)
            return false;
        else
            i++;
    }

}

int main()
{
    int n;

    char s1[10];
    char s2[20];
    for(int i=0; i < M; i++)
        A[i] = -1;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%s%s",s1,s2);
        //printf("%d\n",getKey(s2));
        if(s1[0] == 'i')
        {
            insert(A,s2);
        }
        else if(s1[0] == 'f')
        {
            if(find(A,s2))
                printf("yes\n");
            else
                printf("no\n");
        }

    }
    return 0;
}


Measured memory_bytes: 6512
/**
 *   Praveen Fulera    
**/

// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

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

typedef long long int ll;
#define endl '\n'
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>

const int mod = 1e9 + 7;
//const int mod = 998244353;

signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  int n; cin >> n;
  set <int> s;
  for(int i = 1; i <= n ; i++){
    int x; cin >> x; s.insert(x);
  }
  cout << ((s.size() == n) ? "YES" : "NO"); 
}


Measured memory_bytes: 9600
/**
 * Calculate the greatest common divisor of `x` and `y` with Euclidean algorithm
 */
tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

/**
 * Calculate the least common multiple of `x` and `y`
 */
fun lcm(x: Long, y: Long): Long = x / gcd(x, y) * y

/**
 * Calculate `a` and `b` such that `a x + b y = [x, y]` where `[x, y]` is GCD of x and y.
 * @return A triple of `(a, b, [x,y])` i.e. `t.first * x + t.second * y = t.third`
 */
fun extendedEuclideanAlgorithm(x: Long, y: Long): Triple<Long, Long, Long> {
    return if (y == 0L) {
        Triple(1, 0, x)
    } else {
        val t = extendedEuclideanAlgorithm(y, x % y)
        Triple(t.second, t.first - t.second * (x / y), t.third)
    }
}

fun main(args: Array<String>) {
    fun g(n: Long, p: Long, q: Long): Long {
        val l = lcm(p, q)

        return n - (n / p + n / q - n / l)
    }

    val (A, B, C, D) = readLine()!!.split(" ").map {it.toLong()}

    println(g(B, C, D) - g(A - 1, C, D))
}


Measured memory_bytes: 37812
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, u;
vector<int>a, b;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u;
		a.push_back(u);
		b.push_back(u);
	}
	sort(all(b));
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int k = lower_bound(all(b), a[i]) - b.begin();
		if (k % 2 != i % 2) ans++;
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 2164
import copy

N = int(input())
A = []
for i in range(N):
    x = int(input())
    A.append(x)
A.sort()
B = copy.copy(A)
ans1 = 0
ans2 = 0

for i in range(1,len(A)-1):
    if i%2 == 0:
        ans1 -= 2 * A.pop(0)
    else:
        ans1 += 2 * A.pop()

if N%2 == 1:
    ans1 = ans1 - A[0] - A[1]
else:
    ans1 = ans1 - min(A[0], A[1]) + max(A[0], A[1])
A = B

for i in range(1,len(A)-1):
    if i%2 == 0:
        ans2 += 2 * A.pop()
    else:
        ans2 -= 2 * A.pop(0)

if N%2  ==1:
    ans2 = ans2 + A[0] + A[1]
else:
    ans2 = ans2 + max(A[0], A[1]) - min(A[0], A[1])
    
print(max(ans1, ans2))


Measured memory_bytes: 8452
#include<stdio.h>
#include<stdlib.h>
#define N 2000002

int A[2000002],B[2000002];
int C[10001];
int n;

int main(){

  int i,j;

  scanf("%d",&n);
  /*
  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  */
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=10000;i++){
    C[i]=0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=10000;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=n;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]=C[A[j]]-1;
  }

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
  if(i!=n)
    printf(" ");
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 16268
#include<bits/stdc++.h>
const int N=1e5+7;
int n,m,e[N][2],ans=0;
bool S[407][407];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d%d",e[i],e[i]+1);
	for(int i=1;i<=n;++i){
		S[i][0]=S[i][i]=1;
		for(int j=m;j;--j){
			int x=e[j][0],y=e[j][1];
			if(S[i][x]){
				if(S[i][y]){
					S[i][0]=0;
					break;
				}
				S[i][y]=1;
			}else if(S[i][y])S[i][x]=1;
		}
	}
	for(int i=1;i<=n;++i)if(S[i][0]){
		for(int j=1;j<i;++j)if(S[j][0]){
			++ans;
			for(int k=1;k<=n;++k)if(S[i][k]&S[j][k]){
				--ans;
				break;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
import math

def solve(n,m,k,a_lst,b_lst):
    #机ごと、読書時間の累積をリストにする。ただし、リスト化はk時間内で読める範囲とする
    aa_lst = make_sum_list(a_lst,k)
    bb_lst = make_sum_list(b_lst,k)
    len_aa = len(aa_lst)
    len_bb = len(bb_lst)

    #A,Bいずれかが一冊も読めないケースを考慮
    if len_aa == 0:
        if len_bb == 0: return 0
        else: return len_bb
    elif len_bb == 0: return len_aa
    
    #全て読めるケースを考慮
    if aa_lst[-1] + bb_lst[-1] <= k: return len_aa + len_bb 
    
    #A,Bいずれかのみ読むケースを考慮
    max_read = max(len_aa,len_bb)

    #リスト範囲でA+Bの最大値を探索する。2分探索を用いる
    for i in reversed(range(len_aa)):
        time = aa_lst[i]
        read = i + 1
        if read + len_bb + 1 <= max_read:
            break
        imax = len_bb-1
        imin = 0
        imid = len_bb // 2
        while True:
            if time + bb_lst[imid] <= k:
                #OK。大を調べる
                if imax - imid <= 1:
                    #探査終了
                    if time + bb_lst[imax] <= k:
                        read += imax + 1
                    else:
                        read += imid + 1
                    break
                imin = imid
            else:
                #NG。小を調べる
                if imid - imin <= 1:
                    #探査完了
                    if time + bb_lst[imin] <= k:
                        read += imin + 1
                    break
                imax = imid
            imid = (imin + imax) // 2
        max_read = max(read,max_read)
    return max_read


def make_sum_list(lst,max):
    sum_lst = []
    sum = 0
    for n in lst:
        sum += n
        if sum > max:
            break
        sum_lst.append(sum)
    return sum_lst

n,m,k = map(int, input().split())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
ans = solve(n,m,k,a_lst,b_lst)
print(ans)

Measured memory_bytes: 41400
#include <iostream>	
#include <string>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
typedef unsigned long long LL;
//
//int com(int n, int r) {
//	if (n == r || n == 0)return 0;
//}
//
//
//int main()
//{
//	string s;
//	int k;
//
//	
//
//	int a['z'] = { 0 };
//	for (int i = 0; i < s.length; i++)
//	{
//		a[s[i]] ++;
//	}
//	int count = 0;
//	for (int i = 'a'; i <'z' ; i++)
//	{
//		if (a[i] != 0)count++;
//	}
//	if (count < s.length > k) {
//		cout << "0"<<endl;
//		return 0;
//	}
//
//
//}

//LL visit(int x, int y) {
//	static int count = 0;
//	if (x == 0 && y == 0) {		
//		count++;
//		return count;
//	}
//if (x != 0)visit(x - 1, y);
//	if (y != 0)visit(x, y - 1);
//
//}
//
//int main() {
//	int N1,N2;
//	cin >> N1>>N2;
//	cout << visit(N1, N2) << endl;
//}

int main() {
	int x, y;
	cin >>x >>y;
	if (x == 2||y==2) {
		cout << "No" << endl;
		return 0;
	}
	bool boolx, booly;
	boolx = (x == 4 || x == 6 || x == 9 || x == 11);
	booly = (y == 4 || y == 6 || y == 9 || y == 11);

	if (booly == boolx)cout << "Yes";
	else cout << "No";
	cout << endl;
}

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

if A.count(0) != 0:
    print(0)
else:
    result = 1
    for e in A:
        result *= e
        if result > 10**18:
            break

    if result > 10**18:
        print(-1)
    else:
        print(result)

Measured memory_bytes: 21708
using System;

namespace Project1
{
    class Func
    {
        int N, W;
        int[,] mem = new int[101, 10001];
        int[] v = new int[1001];
        int[] w = new int[1001]; 
        public Func()
        {
            var line = Console.ReadLine().Trim().Split(' ');
            N = int.Parse(line[0]);
            W = int.Parse(line[1]);
            for (int i = 0; i < N; ++i){
                var line1  = Console.ReadLine().Trim().Split(' ');
                v[i] = int.Parse(line1[0]);
                w[i] = int.Parse(line1[1]);
            }
        }
        public int cal(int n,int h)
        {
            int res=0;
            if (mem[n, h] != 0) return mem[n, h];
            if (n == N) return 0;
            if (h + w[n] > W) res = Math.Max(cal(n + 1, h), res);
            else
            {
                res = Math.Max(cal(n + 1, h), 
                    Math.Max(cal(n + 1, h + w[n]) + v[n], res));
            }
            return mem[n, h] = res;
        }
    }

    class Hello
    {
        static void Main()
        {
            Func n = new Func();
            int ans = n.cal(0, 0);
            Console.WriteLine(ans);
        }
    }
}

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

int main(){
  int a,b,c,d;
  int k1=0,k2=0,k3=0;
  cin >> a >> b >> c >> d;
  ((a>b) ? k1=a-b : k1=b-a);
  ((b>c) ? k2=b-c : k2=c-b);
  ((a>c) ? k3=a-c : k3=c-a);
  if(k1<=d&&k2<=d) cout << "Yes" << endl;
  else if(k3<=d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int search(int A[],int n,int k){
    int i=0;
    A[n]=k;
    while(A[i] != k)
        i++;
    return i != n;
} 
 
int main()
{
    int i,n,A[10000],q,k,sum=0;
     
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
         
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&k);
        if(search(A,n,k))
            sum++;
    }
    printf("%d\n",sum);
     
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P3;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e4 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

ll n, W, w[205], cum[205], dp[205][10005];

ll rec(int i, int j){
    if(dp[i][j]>=0) return dp[i][j];
    if(i==n || j==0) return 1;
    ll res = 0;
    if(j>=w[i]){  // 使う遷移
        res += rec(i+1,j-w[i])%MOD;
    }
    if(j-cum[i+1] < w[i]){  //使わない遷移
        res += rec(i+1,j)%MOD;
    }
    return dp[i][j] = res;
}

int main() {
    cin >> n >> W;
    REP(i,n) cin >> w[i];
    sort(w,w+n);
    reverse(w,w+n);
    REPR(i,n-1) cum[i] = cum[i+1] + w[i];
    REP(i,n+1)fill(dp[i],dp[i]+W+1,-1);
    cout << rec(0,W) << endl;
    return 0;
}



Measured memory_bytes: 18652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string name,type;
  while(cin>>name>>type){
    if(type=="X") break;
    if(type=="D"){
      FOR(i,1,name.size()){
        if(isupper(name[i])){
          name.insert(i++,"_");
        }
      }
      REP(i,name.size()) 
          name[i] = tolower(name[i]);
      cout<<name<<endl;
    }else{
      REP(i,name.size()){
        if(name[i]=='_'){
          name[i+1] = toupper(name[i+1]);
          name.erase(i,1);
        }
      }
      if(type=="U"){
        name[0] = toupper(name[0]);
        cout<<name<<endl;
      }else{
        name[0] = tolower(name[0]);
        cout<<name<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
s = input()

now_try = 0
idx = 0
while idx < len(s) - 1:

    if s[idx] == 'T':
        idx += 1
        continue

    if s[idx] == 'S':
        if s[idx + 1] == 'T':
            s = s[:idx] + s[idx + 2:]
            now_try += 1
            idx = idx - 1 if idx - 1 >= 0 else 0
        else:
            idx += 1

print(len(s))

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

using namespace std;

int main(){
  long N;
  cin >> N;

  // 幸福度
  vector<vector<long> > hp(N, vector<long>(3,0));
  // 幸福度の総和の最大値
  vector<vector<long> > dp(N, vector<long>(3,0));

  for(int i = 0; i < N; i++){
    cin >> hp.at(i).at(0) >> hp.at(i).at(1) >> hp.at(i).at(2);
  }
  
  // 1日目
  for(int j = 0; j < 3; j++){
    dp.at(0).at(j) = hp.at(0).at(j);
  }

  for(int i = 0; i < N -1; i++){
    for(int j = 0; j <= 2; j++){
      for(int k = 0; k <=2; k++){
        if(k!=j) dp[i+1][j] = max(dp[i+1][j], dp[i][k] + hp[i+1][j]);
      }
    }
  }
  long ans = 0;
  for(int j = 0; j < 3; j++){
    ans = max(ans, dp[N-1][j]);
  }
  cout << ans << endl;


}

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

int main(){
    int K; cin>>K;
    if (K<10) {
        cout<<K<<endl;
        return 0;
    }
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for (int i=1;i<10;i++) pq.push(i);
    int k=9;
    ll add;
    while (true){
        ll mn=pq.top(); pq.pop();
        mn = mn*10+mn%10;
        if(mn%10!=0){
            add=mn-1;
            k++;
            if(k==K)break;
            pq.push(add);
        }
        add=mn;
        k++;
        if(k==K)break;
        pq.push(add);
        if(mn%10!=9){
            add=mn+1;
            k++;
            if(k==K)break;
            pq.push(add);
        }
    }
    cout<<add<<endl;
    return 0;
} 

Measured memory_bytes: 1400
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = s
    while True:
        l_len = len(s)
        while True:
            s = s.replace("()", "")
            if len(s) == l_len:
                break
            else:
                l_len = len(s)
        if len(s) == 0:
            print(t)
            exit()
        else:
            if s[0] == ")":
                s = "".join((list("(") + list(s)))
                t = "".join((list("(") + list(t)))
            else:
                s = "".join((list(s)) + list(")"))
                t = "".join((list(t)) + list(")"))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);

// ===

const SIZE: usize = 80;

fn main() {
    let (a, b): (usize, usize) = read();
    let mut f = vec![vec![0; SIZE]; SIZE];
    for i in 0..SIZE/2 {
        for j in 0..SIZE {
            f[i][j] = 1;
        }
    }
    let mut cnt = a;
    for i in 0..SIZE/4 {
        for j in 0..SIZE/2 {
            if cnt >= 2 {
                cnt -= 1;
                f[i*2][j*2] ^= 1;
            }
        }
    }

    let mut cnt = b;
    for i in SIZE/4+1..SIZE/2 {
        for j in 0..SIZE/2 {
            if cnt >= 2 {
                cnt -= 1;
                f[i*2][j*2] ^= 1;
            }
        }
    }

    println!("{} {}", SIZE, SIZE);
    for i in 0..SIZE {
        for j in 0..SIZE {
            if f[i][j] == 0 {
                print!(".");
            } else {
                print!("#");
            }
        }
        println!();
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int N, x;
  scanf("%d %d", &N, &x);

  if (x == 1 || x == 2*N-1) {
    puts("No");
    return 0;
  }

  vector<int> a;
  REP(i, 2*N-1) a.push_back(i+1);

  int rot = (x - N + 2*N-1) % (2*N-1);
  rotate(a.begin(), a.begin() + rot, a.end());
  puts("Yes");
  for (int x: a) printf("%d\n", x);
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pb push_back
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  while (N != 0) {
    N /= K;
    ans += 1;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;

  map<int, int> mp;
  for (int ai : a) mp[ai]++;

  const int N = 1000005;
  vector<int> b(N);

  vector<int> a2 = a;
  sort(all(a2)); // debuged, a to a2
  a2.erase(unique(all(a2)), a2.end());
  for (int ai : a2) {
    for (int j = ai * 2; j < N; j += ai) {
      b[j] = 1;
    }
  }
  int ans = 0;
  for (int ai : a) {
    if (b[ai]) {

    } else {
      if (mp[ai] >= 2) {

      } else {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 17936
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	a=int(input())
	b=int(input())
	print(6-a-b)




	
if __name__ == "__main__":
	main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
	int a,x,i;
	x=100000;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		x=x*0.05+x;
		if(x%1000>0){
			x=x-x%1000+1000;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	string s;
	cin >> s;

	map<char,int> cnt;
	rep(i,0,s.size()) ++cnt[s[i]];
	
	cout << min({cnt['K'],cnt['U'],cnt['P'],cnt['C']}) << endl;
}

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

Measured memory_bytes: 1192
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 100000
const double INF = 1e50;
 
typedef pair<double,double> P;
 
int N;
P A[MAX_N]; 
 
bool compare_y(const P &a,const P &b){
  return a.second < b.second;
}
  
double closest_pair(P *a, int n){
  if(n <= 1) return INF;
  int m = n / 2;
  double x = a[m].first;
  double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);

  vector<P> b;
  for(int i=0;i<n;i++){
      if(fabs(a[i].first - x) >= d) continue;
      for(int j=0;j<b.size();j++){
          double dx = a[i].first - b[b.size() - j - 1].first;
          double dy = a[i].second - b[b.size() - j - 1].second;
          if(dy >= d) break;
          d = min(d, sqrt(dx * dx + dy * dy));
      }
    b.push_back(a[i]);
  }
  return d;
}
 
void solve(){
  sort(A,A+N);
  printf("%.8f\n",closest_pair(A,N));
}
 
int main(){
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    scanf("%lf%lf",&A[i].first,&A[i].second);
  }
  solve();
  return 0;
}

Measured memory_bytes: 6080
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for _ in range(n)]

if a1[0] in b and a1[1] in b and a1[2] in b:
  print('Yes')
elif a2[0] in b and a2[1] in b and a2[2] in b:
  print('Yes')
elif a3[0] in b and a3[1] in b and a3[2] in b:
  print('Yes')
elif a1[0] in b and a2[0] in b and a3[0] in b:
  print('Yes')
elif a1[1] in b and a2[1] in b and a3[1] in b:
  print('Yes')
elif a1[2] in b and a2[2] in b and a3[2] in b:
  print('Yes')
elif a1[0] in b and a2[1] in b and a3[2] in b:
  print('Yes')
elif a1[2] in b and a2[1] in b and a3[0] in b:
  print('Yes')
else:
  print('No')

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

int main()
{
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
 

    return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string.h>
#include<set>
#define inf 0x3f3f3f3f
using namespace std;
int a[10];
int main()
{
    int num;
    int n;
    memset(a,0,sizeof(a));
    cin>>num>>n;
    for(int i=0; i<n; i++)
    {
        int nn;
        scanf("%d",&nn);
        a[nn]++;
    }
    for(int i=num;; i++)
    {
        int flag=1;
        int nuu=i;
        while(nuu)
        {
            int c=nuu%10;
            if(a[c])
            {
                flag=0;
                break;
            }
            nuu/=10;
        }
        if(flag)
        {
            printf("%d\n",i);
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<char,int> mp;
    REP(i,n) {
        char c; cin >> c;
        mp[c]++;
    }
    if (mp.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int max_N = 100005;

int N;

vector<vector<pii>> g(max_N, vector<pii>());
vector<int> c(max_N, -1);

void dfs(int x){
	for(pii pa : g[x]){
		int y = pa.first;
		int w = pa.second;

		if(c[y] != -1) continue;

		if(w % 2 == 0){
			c[y] = c[x];
		}else{
			c[y] = 1 - c[x];
		}

		dfs(y);
	}
}

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

	cin >> N;

	rep(i, N-1){
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		g[u].push_back((pii){v, w});
		g[v].push_back((pii){u, w});
	}

	c[0] = 0;
	dfs(0);

	rep(i, N){
		cout << c[i] << endl;
	}

}


Measured memory_bytes: 8448
// ARC 059 C - いっしょ 2016/08/13

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int min_cost=2000000000;
    int cost_sum=0;
    for(int i=-100;i<=100;++i){
        rep(j ,n){
            cost_sum+=pow(i-a[j],2);
        }
        if ( min_cost >= cost_sum ) min_cost = cost_sum;
        cost_sum = 0; 
    }
    cout << min_cost << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
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 size(int a) {
		return par[root(a)];
	}

	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の木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //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, k;
		cin >> n >> k;
		int x = 1;
		rep(i, 0, n) {
			if (x < k)x *= 2;
			else x += k;
		}
		cout << x << endl;
		return 0;
	}



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

#define N 1010

#define max(a, b) (a < b ? b : a)

int c[N][N];
char a[N], b[N];

int lcs(void)
{
  const int a_size = strlen(a) - 1; 
  const int b_size = strlen(b) - 1;
  int i, j;

  memset(c, 0, sizeof(c));

  for (i = 1; i < a_size + 1; ++i) {
    for (j = 1; j < b_size + 1; ++j) {
      int mx = max(c[i][j - 1], c[i - 1][j]);
      if (a[i - 1] == b[j - 1]) {
        mx = max(mx, c[i - 1][j - 1] + 1);
      }
      c[i][j] = mx;
    }
  }

  return c[a_size][b_size];
}

int main( )
{
  
  int n, i;
  scanf("%d\n", &n);
  i = 0;
  while(i< n){
  i++;
    fgets(a, N, stdin);
    fgets(b, N, stdin);
    printf("%d\n", lcs());
  }
  return 0;
}


Measured memory_bytes: 5844
from sys import stdin

n = int(stdin.readline().strip())
d, x = [int(x) for x in stdin.readline().split()]

a_lst = []
for _ in range(n):
  a_lst.append(int(stdin.readline().strip()))

print(sum([(d - 1) // a + 1 for a in a_lst]) + x)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int V_MAX = 1e7+3;

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll W;cin >> W;
  int M = 4;
  vector<vector<ll> > item(M);
  ll weight = 0;
  rep(i,N){
    ll w,v;cin >> w >> v;
    if(i==0) weight = w;
    int num = w-weight;
    item[num].push_back(v);
  }
  rep(i,M) sort(all(item[i]),greater<ll>());
  map<ll,ll> mp;
  mp[0] = 0;
  rep(i,M){
    for(ll &v : item[i]){
      for(auto itr = mp.rbegin(), mp_rend = mp.rend();itr != mp_rend; ++itr){
        ll pw = itr->first;
        ll pv = itr->second;
        ll nw = pw + weight + i;
        if(nw <= W){
          if(mp.count(nw))mp[nw] = max(mp[nw], pv+v);
          else mp[nw] = pv+v;
        }
      }
    }
  }
  ll maximum = 0;
  for(auto itr = mp.begin(), mp_end = mp.end();itr != mp_end; ++itr) maximum = max(maximum,itr->second);

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


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	int ans = k;
	for(int i=0; i<n-1; i++){
		ans *= k-1;
	}

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc156/tasks/abc156_b>
 問題文============================================================
 B - Digits
 =================================================================
 解説=============================================================

 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    ll T = 1;
    while(T <= N){
        res++;
        T *= K;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
  
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
  
class Point{
    public:
        double x, y;
  
        Point(double x = 0, double y = 0): x(x), y(y) {}
  
        Point operator + (Point p){ return Point(x + p.x, y + p.y);}
        Point operator - (Point p){ return Point(x - p.x, y - p.y);}
        Point operator * (double a){ return Point(a * x, a * y);}
        Point operator / (double a){ return Point(x / a, y / a);}
  
        double abs(){ return sqrt(norm());}
        double norm(){ return x * x + y * y;}
  
        bool operator < (const Point &p) const{
            return x != p.x ? x < p.x : y < p.y;
        }
  
        bool operator == (const Point &p) const{
            return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
        }
};
  
struct Segment {
    Point p1, p2;
};
typedef Segment Line;
  
class Circle{
    public:
        Point c;
        double r;
        Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};
  
typedef Point Vector;
typedef vector<Point> Polygon;
  
double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}
  
Point project(Segment s, Point p){
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}
  
Point getCrossPoint(Segment s1, Segment s2){
    Vector base = s2.p2 - s2.p1;
    double d1 = abs(cross(base, s1.p1 - s2.p1));
    double d2 = abs(cross(base, s1.p2 - s2.p1));
    double t = d1 / (d1 + d2);
    return s1.p1 + (s1.p2 - s1.p1) * t;
}
  
double getDistance(Point a, Point b){
    return (a - b).abs();
}
  
pair<Point, Point> getCrossPoints(Circle c, Line l){
    Vector pr = project(l, c.c);
    Vector e = (l.p2 - l.p1) / (l.p2 - l.p1).abs();
    double base = sqrt(c.r * c.r - (pr - c.c).norm());
    return make_pair(pr + e * base, pr - e * base);
}
  
double arg(Vector p){return atan2(p.y, p.x);}
Vector polar(double a, double r){return Point(cos(r) * a, sin(r) * a);}
  
pair<Point, Point> getCrossPoints(Circle c1, Circle c2){
    double d = (c1.c - c2.c).abs();
    double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
    double t = arg(c2.c - c1.c);
    return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
  
int main(){
    int n;
    Point p[3];
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            cin >> p[j].x >> p[j].y;
        }
        pair<Point, Point> pp = getCrossPoints((Circle){p[0], 400.0}, (Circle){p[1], 400.0});
        pair<Point, Point> pp2 = getCrossPoints((Circle){p[0], 400.0}, (Circle){p[2], 400.0});
        Point P = getCrossPoint((Line){pp.first, pp.second}, (Line){pp2.first, pp2.second});
        printf("%.3f %.3f %.3f\n", P.x, P.y, getDistance(p[0], P));
    }
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int q;
    cin >> s >> q;
    bool rev = false;
    string front,back;
    for(int i=0; i<q; i++){
        int a,b;
        cin >> a;
        if(a == 1){
            rev = !rev;
            continue;
        }
        cin >> b;
        string t;
        cin >> t;
        if((rev && b == 2) || (!rev && b == 1)){
            //front
            front += t;
            //s = t +s;
        }else{
            back += t;
            //s = s + t;
        }
        // cout << s << endl;
    }
    reverse(front.begin(), front.end());
    s = front + s + back;
    if(rev){
        string t(s.rbegin(), s.rend());
        s = t;
    } //reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1308
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll xx,yy,aa,bb,cc;
	cin>>xx>>yy>>aa>>bb>>cc;
	pair<ll,ll> p[aa+bb+cc];
	ll x,y,z,n;
	n=aa+bb+cc;
	for(int a=0;a<n;a++)
	{
		cin>>p[a].fi;
		if(a<aa)
		p[a].se=0;
		else if(a<aa+bb)
		p[a].se=1;
		else 
		p[a].se=2;
	}
	sort(p,p+n);
	z=xx+yy;
	x=xx;
	y=yy;
	ll ans=0;
	for(int a=n-1;a>=n-z;a--)
	{
		if(x>0)
		{
			if(p[a].se==0)
			{
				ans+=p[a].fi;
				x--;
			}
		}
		if(y>0)
		{
			if(p[a].se==1)
			{
				ans+=p[a].fi;
				y--;
			}
		}
	}
	if(x>0&&y>0)
	{
		ans=0;
		for(int a=n-1;a>=n-z;a--)
		{
			ans+=p[a].fi;
		}
	}
	else 
	{
		if(x>0)
		{
			for(int a=n-1;a>=n-z;a--)
			{
				if(p[a].se==2)
				{
					ans+=p[a].fi;
					x--;
					if(x==0)
					break;
				}
			}
			if(x>0)
			{
				for(int a=n-z-1;a>=0;a--)
				{
					if(p[a].se==0||p[a].se==2)
					{
						ans+=p[a].fi;
						x--;
						if(x==0)
						break;
					}
				}
			}
		}
		else 
		{
			for(int a=n-1;a>=n-z;a--)
			{
				if(p[a].se==2)
				{
					ans+=p[a].fi;
					y--;
					if(y==0)
					break;
				}
			}
			if(y>0)
			{
				for(int a=n-z-1;a>=0;a--)
				{
					if(p[a].se==1||p[a].se==2)
					{
						ans+=p[a].fi;
						y--;
						if(y==0)
						break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
n, m = map(int, input().split())

INF = 10**10

# Warshall-Floyd
dist = [[INF for _ in range(n)] for _ in range(n)]
edge = []
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1
    dist[a][b] = c
    dist[b][a] = c
    edge.append([a, b, c])

for i in range(n):
    dist[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])

ans = m
for e in edge:
    flag = False
    i, j, c = e
    for s in range(n):
        if flag:
            break
        for t in range(n):
            if dist[s][i]+c+dist[j][t] == dist[s][t]:
                flag = True
                break
    if flag:
        ans -= 1
print(ans)

Measured memory_bytes: 44140
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextLineInt() []int {
	arr := strings.Split(nextLine(), " ")
	var ret []int
	for _, v := range arr {
		x, _ := strconv.Atoi(v)
		ret = append(ret, x)
	}
	return ret
}

type Pair struct {
	First int
	Second int
}

type Pairs []Pair

func (s Pairs) Len() int {
	return len(s)
}

func (s Pairs) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s Pairs) Less(i, j int) bool {
	return s[i].First > s[j].First
}

func main() {
	var n int
	arr := nextLineInt()
	n = arr[0]
	result := []Pair{}
	for i := 0; i < n; i++ {
		result = append(result, Pair{0, i})
	}
	for i := 0; i < n * (n - 1) / 2; i++ {
		arr := nextLineInt()
		A := arr[0]
		B := arr[1]
		C := arr[2]
		D := arr[3]
		if C > D {
			result[A-1].First += 3
		} else if C < D {
			result[B-1].First += 3
		} else {
			result[A-1].First++
			result[B-1].First++
		}
	}
	sort.Sort(Pairs(result))
	var ans [111]int
	point := 1000000000
	top := 0
	for i, r := range result {
		// 前の人よりポイントが低い
		if point > r.First {
			top = i + 1
			point = r.First
		}
		ans[r.Second] = top
	}
	for i := 0; i < n; i++ {
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 1884
s = gets.chomp.split("")
n = s.count
t1 =  s[0..((n-1)/2)-1]
t2 =  s[(n+3)/2-1..n-1]

def kaibun?(arr)
  (arr.count/2).times do |i|
    unless arr[i] == arr[-(i+1)]
      return false
    end
  end
  true
end

if kaibun?(s) && kaibun?(t1) && kaibun?(t2)
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788