akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,a[1001000];
int main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	if(n==1){
		cout<<(a[1]&1?"Second\n":"First\n");
		return 0;
	}
	sort(a+1,a+n+1,greater<int>());
	int x=1,y=1;
	while(x<n&&a[x+1]>=y+1) x++,y++;
	int k1=a[x]-y,k2=0;
	while(x+k2<n&&a[x+k2+1]>=y) k2++;
	if(~k1&1&&~k2&1) puts("Second");
	else puts("First");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u) a--;
    if(t == u) b--;
    printf("%d %d\n", a, b);
    return 0;
}

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

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n/10==9||n%10==9)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

typedef struct {
	int num;
	int val;
}pair;

#define ms_valtype pair

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a.val - b.val;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, i, j, k, c;
	scanf("%d", &N);
	pair *A = (pair *)malloc(sizeof(pair) * (1 << N));
	for(i = 0; i < (1 << N); i++){
		scanf("%d", &A[i].val);
		A[i].num = i;
	}
	sort(A, (1 << N));
	int *first = (int *)malloc(sizeof(int) * (1 << N));
	int *second = (int *)malloc(sizeof(int) * (1 << N));
	for(i = 0; i < (1 << N); i++){
		first[i] = 0;
		second[i] = 0;
	}
	for(i = (1 << N) - 1; i >= 0; i--){
//		printf("i = %d\n", i);
//		printf("A = (%d, %d)\n", A[i].num, A[i].val);
		if(second[A[i].num] > 0){
			continue;
		}
		else{
			c = (((1 << N) - 1) ^ A[i].num);
			j = c;
			do{
//				printf("j = %d\n", j);
				k = (A[i].num ^ j);
				if(first[k] == 0){
					first[k] = A[i].val;
				}
				else if(second[k] == 0){
					second[k] = A[i].val;
				}
				j = (c & (j - 1));
			}while(j != c);
		}
/*		printf("first:\n");
		for(j = 0; j < (1 << N); j++){
			printf("%d ", first[j]);
		}
		printf("\n");
		printf("second:\n");
		for(j = 0; j < (1 << N); j++){
			printf("%d ", second[j]);
		}
		printf("\n");
*/	}
	int ans = 0;
	for(i = 1; i < (1 << N); i++){
		ans = max(ans, first[i] + second[i]);
		printf("%d\n", ans);
	}
	return 0;
}

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

typedef long long ll;

ll ans=0;

ll gcd(ll x,ll y){
	if(y==0){
		return x;
	}else{
		ans+=2*(x/y)*y;
		ll z=gcd(y,x%y);
		return z;
	}
}

int main(){
	ll n,x;
	cin>>n>>x;
	x=min(x,n-x);
	ll g=gcd(n-x,x);
	ans+=(n-g);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef pair<ll, pll> plll;
typedef vector<pair<int, pii>> viii;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tc int tt;cin>>tt;while(tt--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

const int N = 2e5+1;

int p[N];

void build(int n) {
	for (int i = 0;i < n;i++)
		p[i] = i;
}

int findset(int a) {
	return p[a] == a ? a : p[a] = findset(p[a]);
}

void unionset(int a, int b) {
	p[findset(a)] = findset(b);
}

int main() {
	fio;
	int n, m;
	cin >> n >> m;
	build(n + 1);
	while (m--) {
		int u, v;
		cin >> u >> v;
		unionset(u, v);
	}
	vi ans(n + 1);
	for (int i = 1;i <= n;i++)
		ans[findset(i)]++;
	cout << *max_element(all(ans)) << '\n';
}


Measured memory_bytes: 11084
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int a,b,n,s=0,mod=1000000007;
  cin>>a>>b>>n;
  int l=0,r=1e15+9;
  while(r-l>1){
    int mid=(l+r)/2;
    if(mid&&(a-b)>=1e18/mid){
      r=mid;
      continue;
    }
    int c=n-mid*(a-b);
    if( c+a-b>=a && c>=0 )l=mid;
    else r=mid;
  }
  cout<< (((n-(l%mod)*(a-b))%mod)+((l%mod)*(a%mod)))%mod <<endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int W, H, x, y, r;

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

	if ((x < r || y < r) || ((W - r) < x || (H - r) < y))
		printf("No\n");
	else
		printf("Yes\n");
	
	return (0);
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n,k,j,i;
cin>>n>>k;
ll h[n],temp[k+1],dp[n];
temp[0]=0;
for(i=0;i<n;i++)
cin>>h[i];
dp[0]=0;
dp[1]=abs(h[0]-h[1]);
for(i=2;i<n;i++)
{
for(j=1;j<=i;j++)
{
if(j<=k)temp[j]=dp[i-j]+abs(h[i]-h[i-j]);
else break;
}
dp[i]=*min_element(temp+1,temp+j);
}
cout<<dp[n-1]<<"\n";
return 0;
}




Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・0を除く左端：N,N-1,...の順に並ぶとする。
・0は左から順に、z_N,z_{N-1},...と並ぶ（もとの正体）
・小さい数から順に処理する。n以下の数とz_n,...,z_1を並べたとき、先頭の0の個数ごとに値を持つ
"""

import numpy as np

N,K = map(int,read().split())

if K == 1:
    print(1)
    exit()

MOD = 10 ** 9 + 7

def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]

def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact,fact_inv

U = (N + 10) * (K + 10)
fact, fact_inv = make_fact(U)

# 最初はz_1,1,1,...と並べるしかない。左端にzが1つ。
dp = np.array([0,1],np.int64)
for n in range(2,N+1):
    prev = dp
    dp = np.zeros(n+1,np.int64)
    """
    dp[i] には、prev[i-1,i,i+1,...]から遷移してくる。和をとって定数倍。
    累積和をいじったあと定数倍すればよい
    """
    S = prev.sum() % MOD
    np.cumsum(prev,out=prev); prev %= MOD
    dp[1] = S
    dp[2:] = S - prev[:-1]
    """
    n の挿入方法を乗ずる。
    [z^i][n][右側：小さい側が(n-1)K-i+1個、nがK-2個]
    """
    coef = fact[n*(K-1)-1:n*K][::-1].copy()
    coef *= fact_inv[K-2]; coef %= MOD
    coef *= fact_inv[(n-1)*(K-1):(n-1)*K+2][::-1]; coef %= MOD
    dp *= coef; dp %= MOD

answer = dp.sum() % MOD
answer *= fact[N]; answer %= MOD
print(answer)

Measured memory_bytes: 170268
#include<bits/stdc++.h>
#define int long long
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000009
#define garou99 ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
signed main() {
  string s,t;
  cin>>s>>t;
  int m=s.length();
  int n=t.length();
  int mn=INT_MAX,j=0;
  for(int i=0;i<m;i++){
	  int x=i,z=0;
	for(int j=0;j<n;j++){
		if(i+j>=m){
			z=INT_MAX;
			break;
		}
   if(s[i+j]!=t[j])
   z++;
   x++;
	} 
	mn=min(mn,z);
  }
  if(mn==INT_MAX)
  mn=n;
  cout<<mn;
	}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int n, k;
	string s, a("A"), b("B"), c("C");
	cin >> n >> k >> s;
	if (s.substr(k - 1, 1) == "A") {
		s[k - 1] = 'a';
	}
	else if (s.substr(k-1, 1) == "B") {
		s[k - 1] = 'b';
	}
	else if (s.substr(k-1, 1) == "C") {
		s[k - 1] = 'c';
	}
	cout << s << endl;
}



Measured memory_bytes: 256
// Sky is the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
    	int n, a, b;
    	cin >> n >> a >> b;
    	
    	int ans = min(a - 1, n - b) + (b - a)/2 + 1;
    	if ((b - a) % 2 == 0)
    		ans = min(ans, (b - a) / 2);

    	cout << ans << '\n';


    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
L = []
R = []
for loop in range(N):
    l1, r1 = map(int, raw_input().split())
    L += [l1]
    R += [r1]
L.sort(reverse = True)
R.sort()

ans = 0
if L[0] > 0:
    S = L[0]
    L_pre = L[0]
    posL = 1
    posR = 0
    while True:
        R_pre = R[posR]
        posR += 1
        if L_pre < R_pre:
            S += abs(L_pre)
            break
        S += L_pre - R_pre
        L_pre = L[posL]
        posL += 1
        if L_pre < R_pre:
            S += abs(R_pre)
            break
        S += L_pre - R_pre
    ans = S

if R[0] < 0:
    S = abs(R[0])
    R_pre = R[0]
    posL = 0
    posR = 1
    while True:
        L_pre = L[posL]
        posL += 1
        if L_pre < R_pre:
            S += abs(R_pre)
            break
        S += L_pre - R_pre
        R_pre = R[posR]
        posR += 1
        if L_pre < R_pre:
            S += abs(L_pre)
            break
        S += L_pre - R_pre
    ans = max(ans, S)

print ans


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

#define ll long long
#define endl "\n"
#define m 1000000007

ll a[1000005];

void solve() {
  ll n;
  cin >> n;
  ll ans1 = INT_MAX;
  ll ans2 = INT_MAX;
  ll ans3 = INT_MIN;
  ll ans4 = INT_MIN;
  ll x, y;
  ll ans = INT_MIN;
  for (ll i = 0; i < n; ++i) {
    cin >> x >> y;
    ans1 = min(ans1, x+y);
    ans2 = min(ans2, x-y);
    ans3 = max(ans3, x+y);
    ans4 = max(ans4, x-y);
  }
  cout << max(ans, max(ans3-ans1, ans4-ans2)) << endl;
}

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

Measured memory_bytes: 3616
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;
VI G[100010];
VI A, B, C;
int ans[100010];
bool done[100001][11];

void solve(int now, int d, int c) {
	//cout << now << " " << d << " " << c << endl;
	if (done[now][d])return;
	done[now][d] = 1;
	if(ans[now]==0)ans[now] = c;
	if (d == 0)return;
	solve(now, d - 1, c);	
	fore(to, G[now]) solve(to, d - 1, c);
}





signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> M;
	
	REP(i, M) {
		int v, u; cin >> v >> u;
		v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	int op; cin >> op;
	A.resize(op);
	B.resize(op);
	C.resize(op);
	REP(i, op) {
		cin >> A[i] >> B[i] >> C[i];
		A[i]--;
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	reverse(C.begin(), C.end());

	REP(i, op) {
		solve(A[i], B[i], C[i]);
		//cout << A[i] << endl;
	}
	REP(i, N)cout << ans[i] << '\n';

	return 0;
}



Measured memory_bytes: 11124
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>

typedef long long LL;

const int MAXN = 1e5 + 10;

int n, S;
LL ans;
int a[MAXN];
LL b[MAXN];

int main() {
	scanf("%d%d", &n, &S);
	for (int i = 1; i <= n; ++i) scanf("%d%lld", &a[i], &b[i]);
	for (int L = 1, R = n, dir = 2333;;) {
		if (S < a[L]) { ans += a[R] - S; break; }
		if (S > a[R]) { ans += S - a[L]; break; }
		if (b[L] >= b[R]) ans += dir != 0 ? a[R] - a[L] : 0, b[L] += b[R--], dir = 0;
		else ans += dir != 1 ? a[R] - a[L] : 0, b[R] += b[L++], dir = 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int f[100000];
int main()
{
	int n,i,x,y,m,h1,h2,h=0,k;
	scanf("%d%d",&n,&m);
	k=m;
	memset(f,0,sizeof(f));
	while(m--)
	{
		int min1=99999,min2=99999;
		scanf("%d%d",&x,&y);
		for(i=x;i<=y;i++)
		{
			f[i]++;
		}
		h1=min(min1,x);
		h2=max(min2,y);		
	}
	for(i=h1;i<=h2;i++)
	{
		if(f[i]==k)
		h++;
	}
	printf("%d",h);
	return 0;
	
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x; cin >> x;
    long long ans = 0;
    while(x >= 500){
        x-= 500;
        ans += 1000;
    }
    while(x>=5){
        x-=5;
        ans+=5;
    }
    cout << ans << endl;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x, a, b; cin >> x >> a >> b;
    if (b - a <= 0) cout << "delicious" << endl;
    else if (b - a <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, a, n) for (long long i = a; i <= n; i++)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#pragma endregion
int main() {
    IO;
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

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

int main(){

    ll a,b;

    cin >> a >>b;

    ll ans=0;

    for(int i=a;i<=b;i++){
        if(i/10000==i%10&&i/1000%10==i/10%10){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var abcd = Console.ReadLine().Split();
        var a = int.Parse(abcd[0]);
        var b = int.Parse(abcd[1]);
        var c = int.Parse(abcd[2]);
        var d = int.Parse(abcd[3]);
        Console.WriteLine(Math.Max(a * b, c * d));
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
	
	int c=0;
	string s, t;

	while(cin >> s) {
		t=s;
		reverse(t.begin(), t.end());
		s==t ? c++ : c=c ;
	}

	cout << c << endl;

	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int A[n + 1];
	int num = 0, x = 0;
	for(int i = 0; i < n; i++)
		cin >> A[i];
	while(1)
	{
		if(x == 0)
			x += k;
		else
			x += k - 1;
		num++;
		if(x >= n)
		{
			cout << num << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = b; i < (b)+(n); i++)
using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	if (s[0] == 'R' && s[1] == 'R'&&s[2] == 'R') cout << 3;
	else if (s[0] == 'S' && s[1] == 'S'&&s[2] == 'S') cout << 0;
	else if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R'&&s[2] == 'R') cout << 2;
	else cout << 1;
	cout << endl;
}

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

int main() {
  string n;
  int M = 0;
  cin >> n;
  int N = stoi(n);
  int l = n.length();
  
  rep(i, l) {
    M += N%10;
    N /= 10;
  }
  
  if (stoi(n)%M == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/* -------------------------------Solution Sarted--------------------------------------*/
//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5

void solve(){
	int n;
	cin >> n;

	cout << n + n*n + n*n*n << endl;
	
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

Measured memory_bytes: 3664
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
    mini=i
    for j in range(i,n):
        if a[j]<a[mini]:
            mini=j
    tmp=a[i]
    a[i]=a[mini]
    a[mini]=tmp
    if a[i]!=tmp:
        b+=1
print(" ".join(map(str,a)))
print(b)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, i, j, l, r;
    string s;
    vector<int> v;
    cin >> n >> q;
    cin >> s;
    v.push_back(0);
    int c = 0;
    for(i = 0; i < n-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C') c++;
        v.push_back(c);
    }
    for(i = 0; i < q; i++){
        cin >> l >> r;
        cout << v[r-1] - v[l-1] << endl;
    }
}

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

bool prime(int p) {
	bool boolean;
	if (p == 2)boolean = true;
	else {
		FOR(i, 2, p) {
			if (p%i == 0) {
				boolean = false;
				break;
			}
			else if (i == p - 1)boolean = true;
		}
	}return boolean;
}

signed main(void) {
	int X;
	cin >> X;
	int i = 0;
	while (true) {
		if (prime(X + i)) {
			print(X + i);
			break;
		}
		else i++;
	}
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
x=list(map(int,input().split()))

icnt=0
for i in range(n-1):
    xd=x[i+1]-x[i]
    if b>xd*a:
        icnt+=xd*a
    else:
        icnt+=b
    
print(icnt)


Measured memory_bytes: 20036
n, k, c = map(int, input().split())
s = input()

left = []
right = []

i = 0
while i < n:
    if s[i] == 'o':
        left.append(i)
        i += c
        if len(left) == k:
            break
    i += 1
i = n - 1
while i >= 0:
    if s[i] == 'o':
        right.append(i)
        i -= c
        if len(right) == k:
            break
    i -= 1
right.reverse()
ans = []
for i, j in zip(left, right):
    if i == j:
        ans.append(i)
for x in ans:
    print(x + 1)

Measured memory_bytes: 113464
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include<bits/stdc++.h>
using ll = long long;
using namespace std;

int n,k;
int r,s,p;
string t,tmy;
ll sum=0;

void input(){
    cin>>n>>k>>r>>s>>p>>t;
    tmy=t;
}
inline void get(int id){
    if(t[id]=='r'){ tmy[id]='p';sum+=p;}
    else if(t[id]=='s'){tmy[id]='r';sum+=r;}
    else{tmy[id]='s';sum+=s;}
}
inline void get2(int id){
    if(t[id]=='r'){ if(tmy[id-k]!='p'){tmy[id]='p';sum+=p;}else{tmy[id]='a';}}
    else if(t[id]=='s'){ if(tmy[id-k]!='r'){tmy[id]='r';sum+=r;}else{tmy[id]='a';}}
    else{ if(tmy[id-k]!='s'){tmy[id]='s';sum+=s;}else{tmy[id]='a';}}
}

void src(){
    rep(i,n){
        if(i<k){
            get(i);
        }else{
            get2(i);
        }
    }
    cout<<sum;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 512
def main():
    hug = 0
    S = input()

    for i in range(int(len(S)/2)):
        if S[i] !=  S[len(S)-i-1]:
            hug = hug + 1
        
    print(hug) 
 
 
 
if __name__ == '__main__':
    main()

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  using P = pair<int, int>;
  vector<P> ab(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> ab[i].second >> ab[i].first;
  }

  sort(ab.begin(), ab.end());
  int sum = 0;
  bool flag = true;
  for ( int i = 0; i < N; i++ ) {
    sum += ab[i].second;
    if ( sum > ab[i].first ) {
      flag = false;
      break;
    }
  }

  if ( flag ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--) 
 
signed main(){
    fast;
    int n;
    cin >> n;
    string s;
    set<string> a;
    rep(i,0,n){
        cin >> s;
        a.insert(s);
    }
    cout << a.size();
}

Measured memory_bytes: 19244
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <utility>
#include <map>
using namespace std;
using ll = long long;

constexpr ll mod =  998244353;

constexpr int limit = 1e5*3 + 1;
ll u[limit];
ll d[limit];

void init();
ll pow(ll);

int main(){
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  init();

  ll ans = 0;
  for(ll i=0; i<=n && a * i <= k; i++){
    ll sm = a * i;
    if((k - sm) % b == 0){
      ll j = (k - sm) / b;
      if(n >= j){
        ans += ((((u[n] * d[n-i])%mod * d[i])%mod) * (((u[n] * d[n-j])%mod * d[j])%mod))%mod;
        ans %= mod;
      }
    }
  }

  if(ans == 0) ans = 1;

  cout << ans << endl;

  return 0;
}

void init(){
  u[0] = 1, d[0] = 1;
  for(int i=1; i<=limit; i++){
    u[i] = u[i-1]*i;
    u[i] %= mod;
    d[i] = pow(u[i]);
  }
}

ll pow(ll a){
  ll res = 1, n = mod-2;
  while(n > 0){
    if(n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


int main()
{
  ll N;
  scanf("%lld",&N);
  vector<ll> A(N);
  ll s=0;
  for(int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    s+=A[i];
  }

  vector<ll> ans(N, 0);
  for (int i=1; i<N; i+=2) {
    s -= A[i]*2;
  }
  ans[0]=s;
  for (int i=0; i<N-1; i++) {
    int p = i-1;
    if (i==0) p=N-1;
    A[i]-=ans[i]/2;
    A[p]-=ans[i]/2;
    ans[i+1]=A[i]*2;
  }
  for (int i=0; i<N; i++) {
    if (i==0) cout << ans[i];
    else cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int dp[51][2505][51];
int add(int &a, const int &b) {
	a += b;
	if (a >= MOD)a -= MOD;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;

	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int s = 0; s <= K; s++) {
			for (int j = 0; j <= N; j++) {
				if (s + 2 * j <= K) {
					add(dp[i + 1][s + 2 * j][j], dp[i][s][j]);
					
					add(dp[i + 1][s + 2 * j][j + 1], dp[i][s][j]);
					if (j > 0) {
						add(dp[i + 1][s + 2 * j][j - 1], (j * j * dp[i][s][j]) % MOD);
						add(dp[i + 1][s + 2 * j][j], (2 * j * dp[i][s][j]) % MOD);
					}
				}
			} 
		}
	}

	cout << dp[N][K][0] << endl;
}

Measured memory_bytes: 50176
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, x;

int rec(vector<int> a) {
    int res = 0;
    if(a[0] > x) {
        res += (a[0] - x);
        a[0] = x;
    }
    for(int i = 1; i < n; ++i) {
        //cerr << a[i - 1] + a[i] << endl;
        if(a[i - 1] + a[i] > x) {
            res += (a[i - 1] + a[i] - x);
            a[i] = x - a[i - 1];
        }
    }
    return res;
}

void solve() {
	cin >> n >> x;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    auto b = a;
    reverse(all(b));
    cout << min(rec(a), rec(b)) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 16
using namespace std;

int n;
int cost[MAX][MAX];
string s[MAX];
int dp[1<<MAX][MAX];

int getCost(string a,string b)
{//from a to b
  int res = inf;
  for(int i=a.size()-1,st = 0;i>=0 && st < b.size();i--,st++)
    {
      string ca = a.substr(i,a.size()-i);      
      string cb = b.substr(0,st+1);
      if(ca == cb)res = st+1; 
    }
  return res;
}

int main()
{
  while(cin >> n,n)
    {
      rep(i,n)rep(j,n)cost[i][j] = inf;
      rep(i,n)cin >> s[i];
      vector<string> ss;
      rep(i,n)
	{
	  bool contain = false;
	  rep(j,n)
	    {
	      if(i == j)continue;
	      if(s[j].find(s[i]) != string::npos)
		{

		  contain = true;
		  break;
		}
	    }
	  if(!contain)ss.push_back(s[i]);
	}

      n = ss.size();
      rep(i,n)
	{
	  rep(j,n)
	    {
	      if(i == j)
		{
		  cost[i][j] = ss[i].size();
		  continue;
		}
	      int ct = getCost(ss[i],ss[j]);
	      if(ct == inf)cost[i][j] = ss[j].size();
	      else cost[i][j] = ss[j].size() - ct;
	    }
	}
      rep(i,1<<n)rep(j,n)dp[i][j] = inf;
      rep(i,n)dp[1<<i][i] = ss[i].length();

      rep(S,(1<<n))
	{
	  rep(from,n)
	    {
	      if(!((S>>from) & 1))continue;
	      rep(to,n)
		{
		  if((S>>to) & 1)continue;
		  dp[S|(1<<to)][to] = min(dp[S|(1<<to)][to],
					  dp[S][from] + cost[from][to]);
		}
	    }
	}
      int ans = inf;
      rep(i,n)ans = min(ans,dp[(1<<n)-1][i]);

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

Measured memory_bytes: 2248
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------

int main(){
  string a,b;
  cin >> a >> b;
  pair<int,string> A,B;
  A = pair<int,string>(a.size(),a);
  B = pair<int,string>(b.size(),b);
  if(A > B){
    cout << "GREATER\n"; 
  }else if(A < B){
    cout << "LESS\n";
  }else{
    cout << "EQUAL\n";
  }

  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int arr[15];
int main()
{
    int n;
    int k;
    cin>>n>>k;
    for(int i = 0 ; i<k ; ++i)
    {
        int x;
        cin>>x;
        arr[x] = 1;
    }
    while(1)
    {
        int y = n;
        while(y)
        {
            int a = y%10;
            if(arr[a]) break;
            y/=10;
        }
        if(y==0) break;
        n++;
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
        int t[200000];
int main(){
	int n=0;
	long long int ans=0;
	int T=0;
	int i=0;
	cin>>n>>T;
	for(i=0;i<n;i++){
		cin>>t[i];
	}
	ans=T;
	for(i=1;i<n;i++){
		if(T>t[i]-t[i-1]){
			ans=ans+t[i]-t[i-1];
		
		}
		if(T==t[i]-t[i-1] || T<t[i]-t[i-1]){
			ans=ans+T;
	
		}
	}
	cout<<ans;
}	
	

Measured memory_bytes: 1024
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
pq = []
for i in range(N):
    for j in range(N):
        if i==j: continue
        x0,y0 = src[i]
        x1,y1 = src[j]
        pq.append((x1-x0, y1-y0))

ss = set(src)

ans = N
for p,q in pq:
    tmp = 0
    for x,y in src:
        if (x+p, y+q) not in ss:
            tmp += 1
    ans = min(ans, tmp)
print(ans)

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

#define pb push_back
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
#define fo(n) for(int i=1;i<=n;i++)
typedef pair<int,int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    ll n,k;
    cin>>n>>k;
    n = n%k;
    cout<<min(n,k-n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll a,d,n;
bool is_ok[1000010];
void filter(){
    for(int i=0;i<1000010;i++) is_ok[i]=true;
    for(int i=2;i<1000010;i++){
        if(is_ok[i]==true){
            for(int j=i*2;j<1000010;j+=i) is_ok[j]=false;
        }
    }
}
int main(){
    filter();
    //cout<<"abc"<<endl;
    while(1){
        cin>>a>>d>>n;
        if(a==0 && d==0 && n==0) break;
        ll cnt=0;
        ll ans=0;
        ll now=2;
        for(int i=a;i<1000010;i+=d){
            if(is_ok[i]==true && i!=1){
                cnt++;
                ans=i;
                if(cnt==n) break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4064
#include <cstdio>
#include <cstring>
#define maxn 10
using namespace std;
int n,m,ans;
bool to[maxn][maxn],e[maxn];
int d[maxn];
void dfs(int a) {
	if (a>n) {
		for (int i=1;i<n;i++)
			if (!to[d[i]][d[i+1]])
				return;
		ans++;
		return;
	}
	for (int i=1;i<=n;i++)
		if (!e[i]) {
			e[i]=1;
			d[a]=i;
			dfs(a+1);
			e[i]=0;
		}
}
int main() {
	scanf("%d %d",&n,&m);
	memset(to,0,sizeof(to));
	for (int i=1;i<=m;i++) {
		int a,b;
		scanf("%d %d",&a,&b);
		to[a][b]=1;
		to[b][a]=1;
	}
	memset(e,0,sizeof(e));
	ans=0;
	d[1]=1; e[1]=1;
	dfs(2);
	printf("%d\n",ans);
	return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[N] ;
bool visited[N] ;

int main() {
  int n, pos = 1, count = 1 ;
  scanf("%d", &n) ;

  for(int i = 1 ;i<=n ;i++)scanf("%d", &a[i])  ;


  while(!visited[pos]){
    visited[pos] = 1 ;
    pos = a[pos] ;

    if(pos == 2){
      printf("%d", count) ;
      return 0 ;
    }
    count++ ;
  }
  printf("-1") ;
  return 0 ;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll X,N;
    cin >> X >> N;
    ll p[102];
    rep(i,102) p[i] = 0;
    rep(i,N){
        ll P;
        cin >> P;
        p[P]++;
    }
    ll out = 1000;
    rep(i,102){
        if(p[i]==0){
            if(abs(i-X)<abs(out-X)) out = i;
        }
    }
    cout << out << endl;
    return 0;
}


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

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<Integer> T = new ArrayList<Integer>();
		List<Integer> S = new ArrayList<Integer>();
		
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			int val = in.nextInt();
			S.add(val);
		}
		int q = in.nextInt();
		for (int i = 0; i < q; i++) {
			int val = in.nextInt();
			T.add(val);
		}
		
		int cnt = 0;
		for (int i = 0; i < T.size(); i++) {
			int tval = T.get(i);
			for (int j = 0; j < S.size(); j++) {
				if (tval == S.get(j)) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}



Measured memory_bytes: 40172
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18


int main()
{
    int K; cin >> K;
    if (K < 10) {
        cout << K << endl;
        return 0;
    }
    queue<pair<llong, llong>> Q;
    for (int i=1; i<10; i++) {
        Q.push(make_pair(i, i));
    }
    int num_lunlun = 9;
    pair<llong, llong> ans;
    while( !Q.empty() ) {
        auto parent = Q.front(); Q.pop();
        pair<llong, llong> l_child, c_child, r_child;

        if (parent.second > 0) {
            l_child.second = parent.second - 1;
            l_child.first = parent.first * 10 + l_child.second;
            num_lunlun++;
            ans = l_child;
            Q.push(l_child);
            //cout << num_lunlun << ", left :" << ans.first << endl;
            if (num_lunlun >= K) {
                break;
            }
        }

        c_child.second = parent.second;
        c_child.first = parent.first * 10 + c_child.second;
        num_lunlun++;
        ans = c_child;
        Q.push(c_child);
        //cout << num_lunlun << ", center :" << ans.first << endl;
        if (num_lunlun >= K) {
            break;
        }

        if (parent.second < 9) {
            r_child.second = parent.second + 1;
            r_child.first = parent.first * 10 + r_child.second;
            num_lunlun++;
            ans = r_child;
            Q.push(r_child);
            //cout << num_lunlun << ", right :" << ans.first << endl;
            if (num_lunlun >= K) {
                break;
            }
        }
    }
    cout << ans.first << endl;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> s(N);
  for(int i = 0; i < N; i++) cin >> s.at(i);
  sort(s.begin(), s.end());
  for(int i = 0; i < N; i++)
    cout << s.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int m, n, a[100000];
int cnt = 1, ans;

signed main() {
	cin >> m >> n;
	if (m == 2) {
		cnt = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if ((i % 2) && a[i] != 1)cnt++;
			if (!(i % 2) && a[i] != 2)cnt++;
		}
		cout << min(cnt, n - cnt) << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i && a[i - 1] == a[i])cnt++;
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans += cnt / 2;
	cout << ans << endl;
}



Measured memory_bytes: 3884
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int dp[88][88][20000] = {};
const int M = 10000;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int h, w;
  cin >> h >> w;
  vector<vector<int>> g(h, vector<int>(w));
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    cin >> g[i][j];
  }
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    int a;
    cin >> a;
    g[i][j] = abs(g[i][j] - a);
  }
  dp[0][0][M + g[0][0]] = 1;
  dp[0][0][M - g[0][0]] = 1;
  queue<pair<int, int>> que;
  que.push({0, 0});
  vector<vector<int>> vis(h, vector<int>(w));
  vis[0][0] = 1;
  while (que.size()) {
    auto cur = que.front();
    que.pop();
    for (int dx : {1, 0}) for (int dy : {0, 1}) {
      if (dx == dy) continue;
      int x = dx + cur.first;
      int y = dy + cur.second;
      if (x >= h || y >= w) continue;
      for (int i = 0; i < 20000; i++) {
        if (dp[cur.first][cur.second][i]) {
          if (i - g[x][y] >= 0) dp[x][y][i - g[x][y]] = 1;
          if (i + g[x][y] < 20000) dp[x][y][i + g[x][y]] = 1;
        }
      }
      if (!vis[x][y]) {
        vis[x][y] = 1;
        que.push({x, y});
      }
    }
  }
  int ans = 1 << 30;
  for (int i = 0; i < 20000; i++) {
    if (dp[h - 1][w - 1][i]) {
      ans = min(ans, abs(i - M));
      //cerr << i << endl;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 549504
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i!=0:
            t[i],t[i-1]=t[i-1],t[i]
        if "".join(t).count("AGC")>=1:
            return False
    return True

n=int(input())
mod=10**9+7
memo=[{} for i in range(n+1)]

def dfs(last3="TTT",cnt=0):
    if last3 in memo[cnt]:
        return memo[cnt][last3]
    if cnt==n:
        return 1
    ans=0
    for i in "AGCT":
        last4 = last3+i
        if ok(last4):
            ans = ans+dfs(last4[1:],cnt+1)
    memo[cnt][last3]=ans
    return ans

print(dfs()%mod)

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

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int    n;
    string s;

    cin >> n;
    cin >> s;

    if (n % 2 == 1) { cout << "No" << endl; return 0; }
    else {
        rep(i, n / 2) {
            if (s.at(i) != s.at((n / 2) + i)) {
                cout << "No" << endl;

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


    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	R, S, P := ReadInt(), ReadInt(), ReadInt()
	T := ReadString()

	ans := 0
	dp := make([][3]int, N+1+K)
	for k := 0; k < K; k++ {
		max := 0
		for i := k; i < N; i += K {
			for h := 0; h < 3; h++ {
				dp[i+K][h] = Max(
					dp[i][(h+1)%3],
					dp[i][(h+2)%3],
				)
				if T[i] == 'r' && h == 2 {
					dp[i+K][h] += P
				}
				if T[i] == 's' && h == 0 {
					dp[i+K][h] += R
				}
				if T[i] == 'p' && h == 1 {
					dp[i+K][h] += S
				}
				max = Max(max, dp[i+K][h])
			}
		}
		ans += max
	}
	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

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


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

int main(){
  int n, a,now;
  vector<int> nums_v,nums;
  vector<int> nums_count(200000,0);
  long long sum=0,ans=0,b=0,count=0;
  cin >> n;
  rep(i,n){
    cin >> a;
    nums_v.push_back(a);
  }
  nums = nums_v;
  sort(nums.begin(),nums.end());
  now = nums[0];
  rep(i,n){
    if(nums[i] == now){
      count++;
    }else{
      nums_count.at(now) = count;
      sum += count*(count-1)/2;
      now = nums[i];
      count = 1;
    }
  }
  
  nums_count.at(now) = count;
  sum += count*(count-1)/2;
  
  
  rep(i,n){
    b = nums_count[nums_v[i]];
    if(b != 0){
      ans = sum - b + 1;
    }else{
      ans = sum;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 5108
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#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 MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

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)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(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>>;

// }}}

const int N=5e5+10;


int n,one[N],dp[N];
char s[N];
bool inq[N];
void main() {
    R(n);
    scanf("%s",s+1);
    REP1(i,1,n) s[i]-='0';
    for ( int i=n; i>=1; i-- ) {
        if ( s[i]==0 ) one[i]=0;
        else one[i]=one[i+1]+1;
    }
    for ( int i=n; i>=1; i-- ) {
        dp[i]=dp[i+1];
        int l=one[i];
        if ( i+l>n ) continue;
        if ( i+l+1>n || s[i+l+1]==0 ) continue;
        chkmax(dp[i],l+dp[i+l+2]);
        if ( l==1 ) {
            int r=one[i+l+1];
            chkmax(dp[i],r+dp[i+2+r]);
            if ( r>1 ) chkmax(dp[i],r-1+dp[i+2+(r-1)]);
        }
    }
    W(dp[1]);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 4608