akhauriyash/Code-Regression huggingface dataset:
def main():
    s = input()

    for i in {"+","-"}:
        for j in {"+","-"}:
            for k in {"+","-"}:
                eq = s[0]+i+s[1]+j+s[2]+k+s[3]
                if eval(eq) == 7:
                    print(eq + "=7")
                    exit()

import itertools
def main2():
    s = list(input())
    sign = ["+", "-"]
    ops = itertools.product(sign, repeat=3)

    for op in ops:
        tmp = ""
        for i in range(3):
            tmp += s[i]
            tmp += op[i]
        tmp += s[3]
        
        if eval(tmp) == 7:
            print(tmp + "=7")
            exit()

if __name__ == "__main__":
    main2()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,k,a;
set<int> st;

int main(){
	cin >> n >> k;
	REP(i,0,k) cin >> a,st.insert(a);
	
	REP(i,n,n*100){
		string s=to_string(i); bool f=true;
		REP(j,0,s.size()) if(st.count(s[j]-'0')) f=false;
		if(f){cout << i << endl; break;}
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    [n, z, w] <- map strToInt . words <$> getLine
    -- スペース区切り整数の入力
    l <- take 2 <$> reverse . map strToInt . words <$> getLine
    let ans1 = max (abs ((head l) - w)) (abs ((head $ tail l) - head l))
    let ans2 = abs $ l!!0 - w
    -- 出力
    putStrLn . show $ if length l > 1 then ans1 else ans2


Measured memory_bytes: 2300
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll cnt[300005];
ll N;

int main()
{
    cin >> N;
    ll A;
    for(int i =1;i < N;i++)
    {
        cin >> A;
        cnt[A]++;
    }
    for(int i = 1;i <= N;i++)
    {
        cout << cnt[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4724
import java.util.Scanner;

//AtCoder Beginner Contest 158
//D - String Formation
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		StringBuilder head = new StringBuilder();
		StringBuilder tail = new StringBuilder();
		int sw = -1; // -1:末尾 1:先頭

		int Q = Integer.parseInt(sc.next());
		for (int i = 0; i < Q; i++) {
			String t = sc.next();
			if (t.equals("1")) {
				sw *= -1;
			} else {
				String f = sc.next();
				String c = sc.next();
				if (sw == -1) {
					if (f.equals("2")) {
						// 末尾
						tail.append(c);
					} else {
						// 先頭
						head.append(c);
					}
				} else {
					if (f.equals("2")) {
						// 先頭
						head.append(c);
					} else {
						// 末尾
						tail.append(c);
					}
				}
			}

		}
		sc.close();
		if (sw == -1) {
			System.out.print(head.reverse().toString());
			System.out.print(S);
			System.out.print(tail.toString());
		} else {
			System.out.print(tail.reverse().toString());
			System.out.print(new StringBuilder(S).reverse().toString());
			System.out.print(head.toString());
		}
	}
}


Measured memory_bytes: 92212
#include <iostream>
using namespace std;
int main(){
  int n;
  long long int y;
  cin >> n >> y;
  for(int i=0;i<=n;i++) {
    for(int j=(n-i);j>=0;j--){
      for(int k=(n-i-j);k>=0;k--){
        if(((i*10000+j*5000+k*1000)==y)&&((i+j+k)==n)){
          cout << i <<" "<<j <<" " << k<< endl;
          return 0;
        }
      }
    }
  }
  cout <<-1 <<" " <<-1 <<" " <<-1 << endl;
}


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

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

vector<ll> xs;
vector<ll> ys;
vector<ll> zs;

ll calc(const int bits, const int N, const int M) {
    vector<ll> values(N, 0);

    for (int i = 0; i < N; i++) {
        ll acc = 0;
        vector<ll> xyzs = {xs[i], ys[i], zs[i]};
        for (int j = 0; j < 3; j++) {
            int sign = bits & (1 << j);
            if (sign) {
                acc += xyzs[j];
            } else {
                acc -= xyzs[j];
            }
        }
        values[i] = acc;
    }

    sort(values.begin(), values.end());
    reverse(values.begin(), values.end());

    ll ans = 0;
    for (int i = 0; i < M; i++) {
        ans += values[i];
    }
    // printf("bits: %x, ans: %lld\n", bits, ans);
    return ans;
}

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

    xs.resize(N);
    ys.resize(N);
    zs.resize(N);
    for (int i = 0; i < N; i++) {
        ll x, y, z;
        cin >> x >> y >> z;
        xs[i] = x;
        ys[i] = y;
        zs[i] = z;
    }

    ll ans = 0;
    for (int bits = 0; bits < (1 << 3); bits++) {
        chmax(ans, calc(bits, N, M));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def test():
    n = int(input())
    t = [0]*(n+1)
    x = [0]*(n+1)
    y = [0]*(n+1)
    ans = True
    for i in range(n):
        a = list(map(int,input().split()))
        t[i+1] = a[0]
        x[i+1] = a[1]
        y[i+1] = a[2]
    for i in range(n):
        dt = t[i+1] - t[i]
        dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
        if dt < dist or dist%2 != dt%2:
            ans = False
    print("Yes" if ans else "No")


if __name__ == "__main__":
    test()


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

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n;
  cin >> n;
  vector<vector<int>> mat = Make2DVector(n, n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }

  vector<vector<FiniteField>> dp = Make2DVector(n + 1, 1 << n, FiniteField(0));
  vector<vector<int>> dp_solved = Make2DVector(n + 1, 1 << n, 0);

  function<FiniteField(int, int)> solve = [&](int k, int set) -> FiniteField {
    if (dp_solved[k][set]) return dp[k][set];

    if (k == n) return 1;

    FiniteField value = 0;
    for (int i = 0; i < n; i++) {
      if ((set & (1 << i)) == 0) continue;
      if (mat[k][i] == 0) continue;
      value += solve(k + 1, set - (1 << i));
    }
    dp_solved[k][set] = 1;
    dp[k][set] = value;
    return value;
  };
  cout << solve(0, (1 << n) - 1).Value() << endl;
}


Measured memory_bytes: 549244
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 1000005
#define ll long long
#define slld(t) scanf("%I64d",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%I64d\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define ub upper_bound
#define lb lower_bound
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))
#define fil(x) memset(x,MAX,sizeof(x))
#define sws ios::sync_with_stdio(false); cin.tie(0)
#define pi acos(-1)
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I <= (B); ++I)
using namespace std;
const ll INF = 2147483647;
ll digitsum (ll num)
{
    ll sum = 0 ;
    while (num != 0)
    {
        sum+=(num%10);
        num/=10;
    }
    return sum;
}
bool isPrime[MAX+1];
void sieve(int n) 
{
    for(int i = 0; i <= n;++i) 
    {
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= n; ++i) 
    {
        if(isPrime[i] == true) 
        {
            for(int j = i * i; j <= n ;j += i)
                isPrime[j] = false;
        }
    }
}
#define matrix vector< vector<ll> >
matrix matmul(matrix &a, matrix &b){
    int i, j, k, n = a.size();
    matrix ans (n, vector<ll>(n));
    for(i=0;i<n;i++)
        for(j=0;j<n;j++){
            ll temp = 0;
            for(k=0;k<n;k++)    temp = (temp + a[i][k] * b[k][j]) % MOD;
            ans[i][j] = temp;
        }
    return ans;
}
matrix matpwr(matrix &a, ll p){
    int n = a.size();
    matrix ans(n, vector<ll> (n));
    for(int i=0;i<n;i++)    ans[i][i] = 1;
    while(p){
        if(p&1) ans = matmul(ans, a);

        a = matmul(a, a);
        p >>= 1;
    }
    return ans;
}
ll pwr(ll base, ll p, ll mod = MOD){
    ll ans = 1;
    while(p){
        if(p & 1)   ans = (ans * base) % mod;
        base = (base * base) % mod;
        p /= 2;
    }
    return ans;
}
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    return (a*b) / gcd(a, b);
}
const int N = 1e5+5 ;
int n ;
ll a, b ;
ll h[N] ;
bool check(ll mid)
{
    ll ans = 0 ;
    ll x = a - b ;
    REPP(i,1,n) 
    {
        ll temp = h[i] ;
        temp -= mid*b ;
        if(temp>0)
        {
            ans += temp/x ;
            if(temp%x) ans++ ;
        }
    }
    return mid>=ans ;
}
int main()
{
    sws;
    //clock_t clk;
    //clk = clock();
    //freopen("a.in", "r", stdin); 
    //freopen("a.out", "w", stdout);

    cin>>n>>a>>b ;
    REPP(i,1,n) cin>>h[i] ;
    ll l = 1, r = 1e9, mid ;
    while(l<r)
    {
        mid = (l + r) >> 1 ;
        if(check(mid)) r = mid ;
        else l = mid + 1 ;
    }
    cout<<l ;

    //clk = clock() - clk;
    //cout << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=200005,E=524288;
const int M=1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int i,dp[5005][5005],siz[N],tmp[10005];
int head[N],Next[N*2],adj[N*2],k,n,u,v;
long long f[N],ans;
void Push(int u,int v)
{
	Next[++k]=head[u];
	head[u]=k;
	adj[k]=v;
}
void dfs(int i,int fa)
{
	int j,k,l;
	siz[i]=1;
	dp[i][1]=1;
	for(j=head[i];j;j=Next[j])
		if(adj[j]!=fa)
		{
			dfs(adj[j],i);
			for(k=0;k<=siz[i]+siz[adj[j]];++k)
				tmp[k]=0;
			for(k=0;k<=siz[i];++k)
			{
				long long s=0;
				for(l=1;l<=siz[adj[j]];++l)
				{
					tmp[k+l]=(tmp[k+l]+1ll*dp[i][k]*dp[adj[j]][l])%M;
					s=(s+dp[adj[j]][l]*f[l])%M;
				}
				tmp[k]=(tmp[k]-s*dp[i][k])%M;
			}
			for(k=0;k<=siz[i]+siz[adj[j]];++k)
				dp[i][k]=tmp[k];
			siz[i]+=siz[adj[j]];
		}
}
int main()
{
	scanf("%d",&n);
	f[0]=1;
	for(i=2;i<=n;++i)
		f[i]=f[i-2]*(i-1)%M;
	for(i=1;i<n;++i)
	{
		scanf("%d %d",&u,&v);
		Push(u,v);
		Push(v,u);
	}
	dfs(1,0);
	for(i=2;i<=n;i+=2)
		ans=(ans+dp[1][i]*f[i])%M;
	cout<<(ans%M+M)%M;
}


Measured memory_bytes: 102144
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
char S[234][234];
vector<vector<int>> E;

int main() {

	scanf("%d", &N);
	E.resize(N);

	rep(i, N) {
		scanf("%*c");
		rep(j, N) scanf("%c", &S[i][j]);
	}
	rep(i, N) rep(j, N) if (S[i][j] == '1') E[i].push_back(j);

	int ans = -1;
	rep(i, N) {
		vector<int> V(N, 0);
		V[i] = 1;
		queue<int> q;
		q.push(i);
		int curans = 1;
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			for (int e : E[cur]) {
				if (V[e] == 0) {
					V[e] = V[cur] + 1;
					curans = V[e];
					q.push(e);
				}
				else {
					if (V[e] == V[cur] - 1 || V[e] == V[cur] + 1);
					else {
						q = queue<int>();
						curans = -1;
						break;
					}
				}
			}
		}
		ans = max(ans, curans);
	}

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

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define N 10

int main(void)
{
    int first = 0, second = -1, third = -2;
    int height, i = 0;
    
    while (i++ < N) {
        scanf("%d", &height);
        if (height > first) {
            third = second;
            second = first;
            first = height;
        } else if (height > second) {
            third = second;
            second = height;
        } else if (height > third)
            third = height;
    }

    printf("%d\n%d\n%d\n", first, second, third);

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

bool compare(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.second<b.second;
}

int main()
{
    arena
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    
    sort(v.begin(),v.end(),compare);
     
     ll sum=0;
    for(ll i=0;i<n;i++)
    {
        sum+=v[i].first;
        if(sum>v[i].second)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N, x; cin >> N >> x;
  vector<int> A(N);
  rep(i,N) cin >> A[i];

  ll ans = 0;
  rep(i,N) {
    if (i == 0 && A[0] > x) {
      ans += (A[0] - x);
      A[0] = x;
    }
    else if (A[i] + A[i-1] > x) {
      ans += (A[i] + A[i-1] - x);
      A[i] = x - A[i-1];
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 640
N,M = map(int, input().split())
flag = [False]*N
ac = wa = 0
wal = [0]*N

for i in range(M):
  p, s = input().split()
  if s == "AC":
    if flag[int(p)-1] == False:
      ac+=1
      wa+=wal[int(p)-1]
      flag[int(p)-1] = True
  if s == "WA":
    if flag[int(p)-1] == False:
      wal[int(p)-1]+=1

print(ac,wa)

Measured memory_bytes: 10316
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    rep(i,n)
    {
        cin>>b[i];
    }

    ll acount=0;
    ll bcount=0;
    rep(i,n)
    {
        ll t=a[i]-b[i];
        if(t==0)continue;
        if(t>0)
        {
            bcount+=t;
        }
        else
        {
            if((-t)%2==0)
            {
                acount+=abs(t)/2;
            }
            else
            {
                bcount+=1;
                acount+=abs(t)/2+1;
            }
            
        }
        
    }
    if(acount>=bcount)
    {
        sayyes;
    }
    else
    {
        sayno;
    }
    
}


Measured memory_bytes: 384
from collections import defaultdict, deque
def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    cnter = defaultdict(int)

    for i in range(N):
        for j in range(i,N):
            n_step = min(abs(j-i), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(j-X))
            cnter[n_step] += 1
    
    for i in range(1,N):
        print(cnter[i])


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3956
#include<iostream>
#include  <stdio.h>
#include  <cmath>

using namespace std;


int main(){

    int N;
    int L;
    int max;
    int sum;
    cin >> N;

    max = 0;
    sum = 0;
    for( int n = 0 ; n < N ; n++ ){

        cin >> L;

        sum = sum + L;

        if(max < L){
            max     = L;
        }

    }
    if(sum - max > max  ){
        cout << "Yes";
    }
    else{
        cout << "No";
    }





}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long int N,A,B,C,D,E;
int main () {
    cin >> N >> A >> B >> C >> D >> E;
    long long int t =  min(A,min(B,min(C,min(D,E))));
    cout << ((t - 1) + N) / t + 4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(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の根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//A^N mod M を計算する。modしたくなかったらpow使うかM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  ll N;
  cin >> N;
  ll ans;
  ans = modpow(10, N, MOD);
  ans -= modpow(9, N, MOD);
  ans += MOD;
  ans %= MOD;
  ans -= modpow(9, N, MOD);
  ans += MOD;
  ans %= MOD;
  ans += modpow(8, N, MOD);
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 3636
n=int(input())
h=list(map(int,input().split()))
answer='Yes'
max_num=h.index(max(h))
if n!=1:
  for a in range(n-max_num-1):
    if h[max_num]-h[a+max_num+1]>=2:
      answer='No'
      break
  for i in range(1,n-1):
    if h[i-1]-h[i]>1:
      answer='No'
      break
    elif h[i-1]-h[i]==1:
      if h[i]-h[i+1]>0:
        answer='No'
        break
print(answer)

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
bool solve(){
	int N,H;
	cin>>N>>H;
	vector<int> deg(2*H+3);
	vector<bool> is(2*H+3,false);
	int S = 2*H+2;
	int V = 2*H+3;
	is[S] = true;

	bool e[403][403]={};
	rep(i,V) e[i][i] = 1;


	rep(i,N){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int s = (c==0?a:H+1+c);
		int t = (d==0?H+1+b:d);
		deg[s]++;
		deg[t]--;
		e[s][t] = 1;
		is[s] = 1;
		is[t] = 1;
	}
	rep(i,H+1){
		if(deg[i]<0) return 0;
		if(deg[i]>0) e[S][i] = 1;
		if(deg[i+H+1]>0) return 0;
		if(deg[i+H+1]<0) e[i+H+1][S] = 1;
	}
	rep(i,V) rep(j,V) rep(k,V) if(e[j][i]&&e[i][k]) e[j][k] = 1;
	rep(i,V) if(is[i]){
		if(!(e[S][i]&&e[i][S])) return 0;
	}
	return 1;
}
int main(){
	if(solve()) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 512
N = input()[::-1]
iv = 1
MOD = 10**9+7
dp = [0 for i in range(13)]
dp[0]=1
ls = [0 for i in range(13)]
for i in range(len(N)):
  x = N[i]
  if x=='?':
    for j in range(13):
      for h in range(10):
        ls[(h*iv+j)%13] += dp[j]
    for j in range(13):
      dp[j] = (ls[j]%MOD)
      ls[j] = 0
  else:
    x = int(x)
    for j in range(13):
      ls[(j+x*iv)%13]+=dp[j]
    for j in range(13):
      dp[j] = (ls[j]%MOD)
      ls[j]=0
  iv *= 10
  iv %= 13
print(dp[5])


Measured memory_bytes: 43884
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using Graph = vector<vector<int>>;

int N, M, K, Q;
int t;
int used[200];
void dfs(const Graph &G, vector<tuple<int, int, int>> &ans, int node) {
    t++;
    int d = t;
    used[node] = 1;
    for (auto v : G[node]) {
        if (used[v] == 0) {
            dfs(G, ans, v);
        }
    }
    t++;
    int f = t;
    ans.push_back(make_tuple(node, d, f));
}

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

    cin >> N;
    Graph G(N);
    memset(used, 0, sizeof(used));
    REP(i, N) {
        int u, k;
        cin >> u >> k;
        u--;
        REP(j, k) {
            int v;
            cin >> v;
            v--;
            G[i].push_back(v);
        }
        sort(ALL(G[i]));
    }

    vector<tuple<int, int, int>> ans;
    t = 0;
    REP(u, N) {
        if (used[u] != 1) {
            dfs(G, ans, u);
        }
    }
    sort(ALL(ans));

    REP(i, (int)ans.size()) { cout << get<0>(ans[i]) + 1 << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << endl; }

    return 0;
}



Measured memory_bytes: 3176
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	double a[1100];
	double n, d, p;
	scanf("%lf %lf %lf", &n, &d, &p);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lf", &a[i]);
	}
	double num = 11111111;
	int wz = 0;
	for (int i = 1; i <= n; i++)
	{
		double t = fabs((d - a[i] * 0.006) - p);
		if (t < num)
		{
			num = t;
			wz = i;
		}
	}
	printf("%d",wz);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
const int maxn = 1e5 + 55;
ll n, l, t;
vector<pi> a;
vi f;
ll count(ll p) {
	ll T = t;
	pi t = a[p];
	ll cnt = 0;
	for(auto i : a) {
		if(t.second==i.second) continue;
		ll z = (t.second==1?(i.first-t.first):(t.first-i.first))%l;
		if(z<0) z += l;
		if(z <= 2*T) {
			cnt++;
			cnt += (2ll*T-z)/l;
		}
	}
	return cnt;
}
pi calc(int i) { // {pos, val}
	ll np = count(i);
	if(a[i].second==1) np = i + np;
	else np = i - np;
	np = (np%n + n)%n;
	ll nx = a[i].first;
	if(a[i].second==1)
		nx = (nx+t)%l;
	else
		nx = (l + ((nx-t)%l))%l;
	return {np, nx};
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >>n  >> l >> t;
	a.resize(n);
	for(auto &i : a) {
		cin >> i.first >> i.second;
		if(i.second==1)
			f.pb((i.first+t)%l);
		else
			f.pb((l + ((i.first-t)%l))%l);
	}
	sort(all(f));
	if(n==1) return cout << f[0], 0;
	pi a = calc(0), b = calc(1);
	pi c, d;
	if(n==2) c = b;
	else c = calc(2);
	if(n<4) d = b;
	else d = calc(3);
	//for(auto i : f) cout << i << " "; cout << "\n";
	//cout << a.first << " " << a.second << "\n";
	//cout << b.first << " " << b.second << "\n";
	//return 0;
	int s = 0;
	while(f[(a.first+s)%n] != a.second || f[(b.first+s)%n] != b.second || f[(c.first+s)%n] != c.second || f[(d.first+s)%n] != d.second) s++;
	for(int i = 0; i < n; i++) cout << f[(i+s)%n] << "\n";
}


Measured memory_bytes: 3700
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func main() {
	var a int
	fmt.Scan(&a)

	var b float64
	fmt.Scan(&b)

	fmt.Println(a * int((b+0.0001)*100) / 100)
}


Measured memory_bytes: 1856
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let u = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let v = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        g[u].push(v);
    }
    let s: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
    let t: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;

    let mut dp = vec![vec![1 << 30; 5]; n + 1];
    dp[s][0] = 0;

    let mut q = std::collections::VecDeque::new();
    q.push_back((s, 0));
    while let Some((v, p)) = q.pop_front() {
        for &nv in g[v].iter() {
            if dp[nv][(p + 1) % 3] == (1 << 30) {
                dp[nv][(p + 1) % 3] = min(dp[nv][(p + 1) % 3], dp[v][p] + 1);
                q.push_back((nv, (p + 1) % 3));
            }
        }
    }

    if dp[t][0] == 1 << 30 {
        println!("-1")
    } else {
        println!("{}", dp[t][0] / 3);
    }
}


Measured memory_bytes: 20732
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// zero-sum-ranges.rs --- Zero-Sum Ranges
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Failed to parse token")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let n = get!(usize);
    let xs = (0..n).map(|_| read::<i32>()).collect::<Vec<_>>();

    let mut map = BTreeMap::<i64, u64>::new();
    map.insert(0, 1);
    let mut sum = 0i64;

    let ans = xs
        .iter()
        .map(|&x| {
            sum += x as i64;
            sum
        })
        .map(|s| {
            let v = map.get(&s).unwrap_or(&0) + 1;
            map.insert(s, v);

            if 1 < v {
                v - 1
            } else {
                0
            }
        })
        .fold(0, |ans, v| ans + v);

    with_bufwriter(|mut out| writeln!(out, "{}", ans).unwrap());
}


Measured memory_bytes: 10492
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
cnt = 1
rflg = False
rcnt = 1
for r in s:
    if r.count('#')>0:
        if rflg:
            cnt += 1
            rcnt = 1
        rflg = True
    elif rflg:
        print(*ans)
        continue
    else:
        rcnt += 1
        continue
    cflg = False
    ans = []
    for e in r:
        if e=='#':
            if cflg:
                cnt += 1
            cflg = True
        ans.append(cnt)
    for _ in range(rcnt):
        print(*ans)

Measured memory_bytes: 4180
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

const std::string RGB = "RGB";

int x, y;
short fld[10][10];

struct State
{
	short st[10][10];
	int cnt;

	State( short fld[10][10], int cnt )
	:	cnt( cnt )
	{
		rep( i, y )
			rep( j, x )
				st[i][j] = fld[i][j];
	}
};

void paint( int px, int py, int prvc, int c )
{
	static const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };

	if( fld[py][px] != prvc )
		return;

	fld[py][px] = c;

	rep( i, 4 )
	{
		int nx = px+dx[i], ny = py+dy[i];

		if( nx >= 0 && nx < x && ny >= 0 && ny < y && fld[ny][nx] == prvc )
			paint( nx, ny, prvc, c );
	}

	return;
}

int main()
{
	while( scanf( "%d%d", &x, &y ), x|y )
	{
		rep( i, y )
		{
			rep( j, x )
			{
				char ch[2];
				scanf( "%s", ch );
				fld[i][j] = RGB.find( ch );
			}
		}

		std::queue<State> que;
		for( que.push( State( fld, 0 ) ); !que.empty(); que.pop() )
		{
			State s = que.front();

			bool fl = true;
			rep( i, y )
			{	
				rep( j, x )
				{	
					fl &= s.st[i][j] == s.st[0][0];
					fld[i][j] = s.st[i][j];
				}
			}

			if( fl )
			{
				printf( "%d\n", s.cnt );

				break;
			}

			rep( c, 3 )
			{
				if( c == **s.st )
					continue;

				if( c )
					memcpy( fld, s.st, sizeof( fld ) );
				paint( 0, 0, **fld, c );
				que.push( State( fld, s.cnt+1 ) );
			}
		}
	}

	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
 if (a % 2 == 0 || b % 2 == 0) {
   cout << "Even" << endl;
 }
 else {
   cout << "Odd" << endl; 
 }    
 }

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
 
int n,m,r;
const int INF=1e7;
int d[2][200][200],z[1000];
typedef pair<int,int> P;
 
int main(){
 
 
    while(scanf("%d %d",&n,&m),n){
	    
	   for(int i=0;i<n;i++){
		  for(int j=0;j<n;j++) d[0][i][j]=d[1][i][j]=INF;
		  d[0][i][i]=d[1][i][i]=0;
	   }
	    
	   for(int i=0;i<m;i++){
		  int x,y,t;
		  char c;
		  scanf("%d %d %d %c",&x,&y,&t,&c);
		  x--; y--;
		  
		  d[c=='L'][x][y]=min(d[c=='L'][x][y],t);
		  d[c=='L'][y][x]=min(d[c=='L'][y][x],t);
	   }
	    
	   for(int k=0;k<n;k++){
		  for(int i=0;i<n;i++){
			 for(int j=0;j<n;j++){
				d[0][i][j]=min(d[0][i][j],d[0][i][k]+d[0][k][j]);
				d[1][i][j]=min(d[1][i][j],d[1][i][k]+d[1][k][j]);
			 }
		  }
	   }
	    
	   scanf("%d",&r);
	   for(int i=0;i<r;i++){
		  scanf("%d",&z[i]);
		  z[i]--;
	   }
	    
	   vector<vector<int> > dp(1000,vector<int>(200,INF));
	   dp[0][z[0]]=0;
 
	   int res=INF;
	   for(int i=1;i<r;i++){
		  for(int j=0;j<n;j++){
						    
			 for(int k=0;k<n;k++){
				dp[i][k]=min(dp[i][k],dp[i-1][j]+d[1][z[i-1]][j]+d[0][j][k]+d[1][k][z[i]]);
				if(i==r-1 && res>dp[i][k]) res=dp[i][k];
			 }
			 dp[i][j]=min(dp[i][j],dp[i-1][j]+d[1][z[i-1]][z[i]]);
			 if(i==r-1 && res>dp[i][j]) res=dp[i][j];
		  }
	   }
 
	   printf("%d\n",res);
	    
    }
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    
    scanf("%d",&n);
    int c=0;

        for(int i=1;i<=9;i++){
            if(n%i==0){
                if(1<=n/i && n/i<=9){
                    c = 1;
                    break;
                }
            }
        } 

    if(c==1) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}


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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int w[100] = {}, h[100] = {};
  for (int i = 0; i < W; i++) w[i] = 1;
  for (int i = 0; i < H; i++) h[i] = 1;

  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1) for (int i = 0; i < x; i++) w[i] = 0;
    if (a == 2) for (int i = x; i < W; i++) w[i] = 0;
    if (a == 3) for (int i = 0; i < y; i++) h[i] = 0;
    if (a == 4) for (int i = y; i < H; i++) h[i] = 0;
  }

  int A = 0, B = 0;
  for (int i = 0; i < W; i++) {
    if (A) A++;
    if (!A && w[i] == 1) A++;
    if (A && !w[i]) {
      A--;
      break;
    }
  }
  for (int i = 0; i < H; i++) {
    if (B) B++;
    if (!B && h[i] == 1) B++;
    if (B && !h[i]) {
      B--;
      break;
    }
  }

  cout << A * B << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import islice

    N = int(input())

    trains = []
    for _ in range(N - 1):
        c, s, f = map(int, input().split())
        trains.append((c, s, f))

    ans = [0] * N
    for i, (ci, si, fi) in enumerate(trains):
        curr = si + ci
        for j, (cj, sj, fj) in enumerate(islice(trains, i + 1, N, 1)):
            if curr < sj: curr = sj
            r = curr % fj
            if r != 0: curr += (fj - r)
            curr += cj
        ans[i] = curr

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#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 reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)


int main() {
	string S;
	int K;
	cin >> S >> K;
	vector<string>V;
	int N = S.size();
	rep(i, N) {
		V.push_back(S.substr(i, 1));
	}
	rep(i, N - 1) {
		V.push_back(S.substr(i, 2));
	}
	rep(i, N - 2) {
		V.push_back(S.substr(i, 3));
	}
	rep(i, N - 3) {
		V.push_back(S.substr(i, 4));
	}
	rep(i, N - 4) {
		V.push_back(S.substr(i, 5));
	}
	sort(V); 
	V.push_back("zzzzzzzzzzz");
	int cnt = 0;
	if (V.size() == 1) {
		cout << V[0] << endl;
		return 0;
	}
	rep(i, V.size()-1) {
		if (V[i] != V[i + 1]) {
			cnt++;
		}
		if (cnt == K) {
			cout << V[i] << endl;
			return 0;
		}
	}
	
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  ll x;
  cin >> x;

  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {
      if (a*a*a*a*a - b*b*b*b*b == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<fstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

//typedef pair<int, int> P;


int N, a[100];
signed main() {
	cin >> N;
	int mx = -INF;
	int mn = INF;
	int idmx, idmn;
	REP(i, N) {
		cin >> a[i];

		if (a[i] > mx) {
			idmx = i;
		}
		if (a[i] < mn)idmn = i;
		mx = max(mx, a[i]);
		mn = min(mn, a[i]);
	}
	print(2 * N - 2);
	if (mx > abs(mn)) {
		REP(i, N) {
			if (i == idmx)continue;
			pe(idmx + 1); print(i + 1);
		}
		REP(i, N - 1) {
			pe(i + 1)print(i + 2);
		}
	}
	else {
		REP(i, N) {
			if (i == idmn)continue;
			pe(idmn + 1); print(i + 1);
		}
		REP(i, N - 1) {
			pe(N-i)print(N-i-1);
		}
	}
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    size_t N;
    std::cin >> N;

    int64_t p = 0;
    std::unordered_map<int64_t, int64_t> m;
    m[0]++;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        auto n = t + p;
        m[n]++;
        p = n;
    }

    size_t count = 0;
    for (auto& v: m) {
        count += v.second * (v.second-1) / 2; // nC2
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 8520
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# 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 INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

string s;

int main() {
	cin >> s;
	reverse(ALL(s));
	while (true) {
		if (s.substr(0, 5) == "maerd")s = s.substr(5, s.size() - 5);
		else if (s.substr(0, 7) == "remaerd")s = s.substr(7, s.size() - 7);
		else if (s.substr(0, 5) == "esare")s = s.substr(5, s.size() - 5);
		else if (s.substr(0, 6) == "resare")s = s.substr(6, s.size() - 6);
		else if (s.size() == 0) {
			cout << "YES" << endl;
			return 0;
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
}

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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;

Node root;
int exist;

Node treeMinmum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaxmum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y=NIL;
  
  if(x->right != NIL) return treeMinmum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  
  if(y->parent == NIL) root = x;
  else if(y==y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

  
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

void find(Node u,int k){
  if(u->key==k){
    printf("yes\n");
    exist = 1;
    return;
  }else{
    if(u!=NIL){
      find(u->left,k);
      find(u->right,k);
    }
    return;
  }
}

int main(){
  root = malloc(sizeof(Node));
  root = NIL;
  
  int n,i,x;
  char com[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }else if(com[0]=='f'){
      exist = 0;
      scanf("%d",&x);
      find(root,x);
      if(exist==0) printf("no\n");
    }
  }

  return 0;
		  
}



Measured memory_bytes: 20432
#include <cstdio>

const int N=200005;

int n,a[N],b[N];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i++)scanf("%d",b+n-i);
    bool success=true;
    for(int i=1,j,t;i<=n&&success;i++)
        if(a[i]==b[i])
        {
            for(int k=1;k<=n&&a[i]==b[i];k++)
                if(b[k]!=b[i]&&a[k]!=b[i])
                    t=b[i],b[i]=b[k],b[k]=t,i++;
            for(int k=1;k<=n;k++)
                if(a[i]==b[i])
                {
                    success=false;
                    break;
                }
        }
    puts(success?"Yes":"No");
    if(success)for(int i=1;i<=n;i++)printf("%d ",b[i]);
    return 0;
}

Measured memory_bytes: 3296