akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCommonRaccoonVsMonster solver = new BCommonRaccoonVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCommonRaccoonVsMonster {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int h = s.nextInt(), n = s.nextInt();
            long res = 0;
            for (int i = 0; i < n; i++)
                res += s.nextInt();
            if (res >= h)
                w.println("Yes");
            else
                w.println("No");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22996
#include <stdio.h>

void swap(int *x, int *y){
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}


int main(void)
{
  int n;
  int i = 0;
  int a[1000], b[1000], c[1000];

  do{
  scanf("%d", &n);
  }while(n > 1000);

  while(i < n){
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    if((1000 >= a[i], b[i], c[i]) && (a[i], b[i], c[i] >= 1)){
      i++;
    }
  }

  for(i = 0; i < n; i++){
    if(a[i] < b[i]) swap(&a[i], &b[i]);
    if(a[i] < c[i]) swap(&a[i], &c[i]);
  }

  for(i = 0; i < n; i++){
    if(a[i]*a[i] == b[i]*b[i] + c[i]*c[i])
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
namespace BasicMath {
    // 二つの値の最大値を求める関数
    static Int Max(const Int a, const Int b);
    // 絶対値を求める
    static UInt Abs(const Int a);
    // 二つの値の最大値を求める関数
    Int Max(const Int a, const Int b) {
        if (a >= b) {
            return a;
        } else {
            return b;
        }
    }
    // 絶対値を求める
    UInt Abs(const Int a) {
        return a > 0 ? a : -a;
    }
}
using namespace BasicMath;

int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    Int d, e, f;
    d = Abs(b - a);
    e = Abs(c - b);
    f = Abs(a - c);
    Int minAbs = Max(Max(d, e), f);
    cout << d + e + f - minAbs << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int        long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define extreme   inline
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define pi        2*acos(0.0)
bool cust(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} 
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"THIS_AND_THIS"<<endl;
#define str       string
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll x,sum=0,mx=INT_MIN;
	for(int i=0;i<n;i++){
		cin>>x;sum+=x;
		mx=max(mx,x);
	}
	cout<<(sum-mx+(mx/2));
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int N;
    string S;
    cin >> N >> S;
    int count=0;
    rep(i,N-2){
        if(S[i]=='A'){
            if(S[i+1]=='B'){
                if(S[i+2]=='C'){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

using namespace std;

void solve() {
    int n, k; cin >> n >> k;
    vector<double> vt(n);
    for (int i = 0; i < n; i++) cin >> vt[i];
    double sum = 0.0, ans = 0.0;
    for (int i = 0; i < k - 1; i++) {
        sum += (vt[i] + 1.0) * 0.5;
    }
    for (int i = k - 1; i < n; i++) {
        sum += (vt[i] + 1.0) * 0.5;
        if (i - k >= 0) sum -= (vt[i - k] + 1.0) * 0.5;
        ans = max(ans, sum);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 1792
#include<stdio.h>
int main() {
    int a, b, c, d, e;
    int x, y;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    x = a * e;
    y = e > c ? b + d*(e - c): b;
    printf("%d\n", x < y ? x : y);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <numeric>
#include <vector>

struct UnionFind {
    std::vector<int> par, sz;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

void solve() {
    int n, q;
    std::cin >> n >> q;

    UnionFind uf(n);
    while (q--) {
        int t, u, v;
        std::cin >> t >> u >> v;

        switch (t) {
            case 0:
                uf.unite(u, v);
                break;
            case 1:
                std::cout << uf.same(u, v) << "\n";
                break;
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4632
N = int(input())
P = [[i, list(map(int, input().split()))] for i in range(N)]

X = sorted([[i, xy[0]] for i, xy in P], key=lambda x: x[1])
Y = sorted([[i, xy[1]] for i, xy in P], key=lambda y: y[1])

Xe = [[X[i][0], X[i+1][0], abs(X[i][1]-X[i+1][1])] for i in range(N-1)]
Ye = [[Y[i][0], Y[i+1][0], abs(Y[i][1]-Y[i+1][1])] for i in range(N-1)]
E = sorted(Xe + Ye, key=lambda e: e[2])


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uf = UnionFind(N)
edge_cnt = 0
MST_cost = 0
i = 0

while edge_cnt < N-1:
    a, b, cost = E[i]
    if not uf.same_check(a, b):
        MST_cost += cost
        uf.union(a, b)
        edge_cnt += 1
    i += 1

print(MST_cost)

Measured memory_bytes: 133124
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    map<ll,ll> m;
    for(ll i=1;i<=100;i++){
        for(ll j=1;j<=100;j++){
            for(ll k=1;k<=100;k++){
                m[i*i+j*j+k*k+i*j+j*k+i*k]++;
                }
            }
        }
    for(ll i=1;i<=n;i++){
        cout<<m[i]<<endl;
    }

    return 0;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};




int main(){
	int n, k, x[1000];
	int ans = 0;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> x[i];
		ans += min(2*x[i], (abs(k-x[i]))*2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
A,B,C,D = list(input())
for op1 in ['+','-']:
    for op2 in ['+','-']:
        for op3 in ['+','-']:
            k = A + op1 + B + op2 + C + op3 + D
            if eval(k) == 7:
                print(k+'=7')
                exit()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  string s,t;
  cin>>s>>t;
  ll c=0;
  fo(i,3)
  {
  	if(s[i]==t[i])
  		c++;
  }
  cout<<c;
  return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

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

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

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

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

    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が属する木の頂点数を得る
        int rx = root(x);
        return vSize[rx];
    }
};

int main()
{
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> fr[N], bl[N];
    UnionFind uf(N);
    REP(i, M)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        fr[a].push_back(b);
        fr[b].push_back(a);
        uf.unite(a, b);
    }

    REP(i, K)
    {
        ll c, d;
        cin >> c >> d;
        c--;
        d--;
        if (uf.same(c, d))
        {
            bl[c].push_back(d);
            bl[d].push_back(c);
        }
    }

    REP(i, N)
    {
        ll ans = uf.size(i) - fr[i].size() - bl[i].size() - 1;
        cout << ans << " ";
    }
}


Measured memory_bytes: 14068
import bisect
N=int(input())
A=[]
ans=0
for i in range(N):
    a=int(input())
    A.append(a)
cl=[A[-1]]
ans=1
for i in range(N-1)[::-1]:
    a=A[i]
    if a>=cl[-1]:
        cl.append(a)
        ans+=1
    else:
        b=bisect.bisect_right(cl,a)
        cl[b]=a
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rforn(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SQ(a) (a)*(a)


int main(){
	fast;
	map<int, int> m;
	for(int i = 0; i < 3; i++){
		int x;
		cin >> x;
		m[x]++;
	}
	
	if((m[5] == 2 && m[7] == 1)){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>

int main(){
    int N;
    int i = 0;
    int k;
    int sun_min = 0;
    int sun_max = 0;
    uint8_t color_table[9] = {0,0,0,0,0,0,0,0,0};
    std::cin >> N;
    if((0 > N) || (N > 100)){
        std::cout << "Invalid N value!" << std::endl;
        return 1;
    }
    while(i < N){
        std::cin >> k;
        if((1 <= k)&&(k <= 399)){
            color_table[0] = 1;
        }else if((400 <= k)&&(k <= 799)){
            color_table[1] = 1;
        }else if((800 <= k)&&(k <= 1199)){
            color_table[2] = 1;
        }else if((1200 <= k)&&(k <= 1599)){
            color_table[3] = 1;
        }else if((1600 <= k)&&(k <= 1999)){
            color_table[4] = 1;
        }else if((2000 <= k)&&(k <= 2399)){
            color_table[5] = 1;
        }else if((2400 <= k)&&(k <= 2799)){
            color_table[6] = 1;
        }else if((2800 <= k)&&(k <= 3199)){
            color_table[7] = 1;
        }else if((3200 <= k)){
            color_table[8]++;
        }else{
            std::cout << "invalid a_i value!" << std::endl;
            return 1;
        }
        i++;
    }
    for (int l = 0; l<8; l++){
        sun_min += color_table[l];
    }
    sun_max = sun_min + color_table[8];
    if(sun_min == 0){
        sun_min = 1;
    }
    std::cout << sun_min << ' ' << sun_max << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  static final int MAX = 10000;
  static int[] rank = new int[MAX];
  static int[] par = new int[MAX];
  static ArrayList<Integer> ansArr = new ArrayList<Integer>();

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();

    for(int i = 0 ; i < n ; i++) {
      rank[i] = 0;
      par[i] = i;
    }

    int com, x, y;
    for(int i = 0 ; i < q ; i++) {
      com = sc.nextInt();
      x = sc.nextInt();
      y = sc.nextInt();
      if(com == 0) unite(x, y);
      else same(x, y);
    }

    // 答え出力
    for(Integer ans: ansArr) System.out.println(ans);
  }

  static int find(int x) {
    if(x == par[x]) return x;
    else return par[x] = find(par[x]);
  }

  static void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }

  static void same(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) ansArr.add(1);
    else ansArr.add(0);
  }
}



Measured memory_bytes: 101024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

ld solve()
{
    ld ans = 0;
    ll N,K;
    cin >> N >> K;
    ld ans1 = 0;
    ll sc = 0;
    for2(i,1,N+1) {
        ans1 = 1;
        sc = i;
        while (sc < K) {
            ans1 /= 2.0;
            sc *= 2;
        }
        ans += ans1;
    }
    cout << setprecision(16) << ans / N << endl;
    //printf("%Lf\n", ans / N);
    return 0;
}

int main()
{
    do {
        solve();
        //cout << solve() << endl;
    } while (DEBUG);
}


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

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	ll n, m, x;
	cin >> n >> m >> x;

	vector<ll> c(n);
	vector<vector<ll>> a(n, vector<ll>(m));

	rep(i, n){
		cin >> c[i];
		rep(j, m) cin >> a[i][j];
	}

	ll INF = 1e15;
	ll ans = INF;
	for(int b = 0; b < (1 << n); b++){
		vector<ll> rik(m, 0);
		ll cost = 0;
		rep(i, n){
			if((b >> i) & 1) {
				cost += c[i];
				rep(j, m) rik[j] += a[i][j];
			}
		}

		bool ok = true;
		rep(j, m) if(rik[j] < x) ok = false;
		if(ok) chmin(ans, cost);
	}

	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <queue>
#include <map>
using namespace std;

map<string,int> mp;
int dx[4]={4,-4,1,-1};

int main(){
    queue<string> q;
    q.push("01234567");
    mp["01234567"]=0;

    while(!q.empty()){
        string s=q.front();q.pop();
        int index0=0;
        for(;index0<=7;index0++){
            if(s[index0]=='0'){
                break;
            }
        }

        string tmp;
        for(int i=0;i<4;i++){
            if((i==2&&index0==3)||(i==3&&index0==4)){
                continue;
            }
            int t=index0+dx[i];
            tmp=s;
            if(t>=0&&t<=7){
                swap(tmp[index0],tmp[t]);
                if(mp.find(tmp)==mp.end()){
                    mp[tmp]=mp[s]+1;
                    q.push(tmp);
                }
            }
        }


    }


    int d;string inp;
    while(cin>>d){
        inp=d+'0';
        for(int i=0;i<7;i++){
            cin>>d;
            inp+=(d+'0');
        }
        cout<<mp[inp]<<endl;
    }

    return 0;
}


Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int mod = 1e9 + 7;
const int MAXN = 2000005;

int n, k;

string solve(string x, int k){
	int pos = x.size();
	while(pos > 0 && x[pos - 1] == x.back()) pos--;
	if(k >= 15){
		string s;
		s.resize(x.size());

		fill(s.begin(), s.end(), x.back());
		return s;
	}
	pos = x.size() - pos;
	pos = (pos << k) - pos;
	pos = min(pos, n);
	for(int i=0; i<pos; i++) x.push_back(x.back());
	reverse(x.begin(), x.end());
	x.resize(n);
	return x;
}

int main(){
	cin >> n >> k;
	string s; cin >> s;
	string ret = s;
	for(int i=0; i<=n; i++){
		string x = s.substr(i, n - i);
		string y = s.substr(n - i, i);
		reverse(y.begin(), y.end());
		if(i == 0) ret = min(ret, solve(x + y, k));
		else ret = min(ret, solve(x + y, k - 1));
	}
	cout << ret << endl;
}


Measured memory_bytes: 384
N = int(input())
happy = [[0] * 3 for _ in range(N + 1)]

for i in range(1, N + 1):
    a, b, c = map(int, input().split())
    happy[i][0] = max(happy[i - 1][1] + a, happy[i - 1][2] + a)
    happy[i][1] = max(happy[i - 1][0] + b, happy[i - 1][2] + b)
    happy[i][2] = max(happy[i - 1][0] + c, happy[i - 1][1] + c)

print(max(happy[-1]))



Measured memory_bytes: 60140
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define rrep(i, N) for(int i=(int)N-1; i>=0; i--)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;

int main() {
  int N, K;
  string S;

  cin >> N >> K;
  cin >> S;

  // しゃくとり法 (l, ..., r)
  int res = 1;
  int l = 0, r = 1;
  int k = (S[0]=='0' ? 1 : 0);
  while(r < N) {
    if(S[r-1]=='1' && S[r]=='0') {
      k++;
      if(k > K) {
        while(true) {
          l++;
          if(S[l-1]=='0' && S[l]=='1') break;
        }
        k--;
      }
    }
    res = max(res, r - l + 1);
    r++;
  }
  
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>

int main() {
	int n, AC, WA, TLE, RE;
  	AC = WA = TLE = RE = 0;
	char read[5];
	scanf("%d", &n);
	while (n--){
		scanf(" %s", read);
		switch (read[0]){
			case 'A': AC++; break;
			case 'W': WA++; break;
			case 'T': TLE++; break;
			case 'R': RE++; break;
		}
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", AC, WA, TLE, RE);
}


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

int main() {
    ll X; cin >> X;

    ll tmp = X%100;
    ll tmp2 = X - X%100;
    ll cnt = 0;
    for(int i=5; i>0; i--){
        cnt += tmp/i;
        tmp = tmp%i;
        //cout << "i = "<< i << " " << tmp << endl;
        if(tmp%i==0) break; 
    }

    if(cnt*100 > tmp2) cout << 0 << endl;
    else cout << 1 << endl;

}


Measured memory_bytes: 256
// Confessions of a Dangerous Mind

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 2e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 3e-16;

/*
	Keep moving forward. Take the Leap of Faith
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

	string s; cin >> s;
	
	string t = "";
	long long ans = 0, n = ll(s.size());
	for(long long i = 0; i < (n - 1) / 2; i++){
		t += s[i];
		string f = s.substr(i + 1, t.size());
		if(t == f) ans = t.size();
	}
	
	cout << ans * 2;
    
    return 0;
}
























Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;


int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
int mat[1001][1001];
queue <pair<int,int>> v;
queue <pair<pair<int,int>,int>> q;
int n,m,maxi;

void lee(){
    int i,j,d,x,y;
    while(!q.empty()){
        i=q.front().first.first;
        j=q.front().first.second;
        d=q.front().second;
        q.pop();
        for(int _=0;_<=3;_++){
            x=i+dx[_];
            y=j+dy[_];
            if(1<=x && x<=n && 1<=y && y<=m){
                if(mat[x][y]>d){
                    mat[x][y]=d;
                    q.push({{x,y},d+1});
                }
            }
        }
    }
}
char c;
int i,j;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(i=1;i<=n;++i){
        for(j=1;j<=m;++j){
            cin>>c;
            if(c=='#'){
                v.push({i,j});
                mat[i][j]=-1;
            }
            else
                mat[i][j]=9999;
        }
    }
    while(!v.empty()){
        q.push({{v.front().first,v.front().second},1});
        v.pop();
    }
    ///
    lee();
    for(i=1;i<=n;++i)
        for(j=1;j<=m;++j)
            maxi=max(maxi,mat[i][j]);
    cout<<maxi<<'\n';
    return 0;
}


Measured memory_bytes: 16656
n = int(input())
x = list(map(int, input().split()))

ans = 10 ** 18
ind= -1
for p in range(0, 101):
    tmp = 0
    for num in x:
        tmp += (num - p) ** 2
    if tmp < ans:
        ans = tmp
        ind = p
print(ans)

Measured memory_bytes: 38640
import java.util.Scanner;

public class Main {

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

		// input
		String input = scan.next();
		char[] tile = input.toCharArray();
		int len = tile.length;

		// check
		int count = 0;
		char color = tile[0];
		for (int i = 1; i < len; i++) {
			if (tile[i] == color) {
				if (color == '1') {
					tile[i] = '0';
					color = '0';
					count++;
				} else {
					tile[i] = '1';
					color = '1';
					count++;
				}
			} else {
				color = tile[i];
			}
		}

		// answer
		System.out.println(count);
	}
}


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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>(x);
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

#define N 100005

int main() {
	ios::sync_with_stdio(0);
    INN(n, k);
    vi a(n);
    int in;
    F(n) {cin>>a[i]; if(a[i]==1) in=i;}
    /*
    int t1 = in-0;
    int t2 = n-in-1;
    int ans=((t1+k-2)/(k-1));
    ans += ((t2+k-2)/(k-1));
    cout<<ans<<endl;
    int ans=0, i=0;
    while(i<in) {
        ans++;
        i += k;
        if(i<k) i--;
    }
    while(i<n) {
        ans++;
        i += k-1;
        //if(i<n) i--;
    }
    */
    if(k==2) {cout<<(n-1)<<endl; return 0;}
    int ans=(n/(k-1));
    if(n%(k-1)>1) ans++;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String input = null;

        try {
            while ((input = in.readLine()) != null) {

                char[] inputChar = input.toCharArray();

                StringBuffer result = new StringBuffer();

                for (int i = inputChar.length - 1; i >= 0; i--) {
                    result.append(inputChar[i]);
                }

                System.out.println(result.toString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Measured memory_bytes: 16864
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define rg register
#define ll long long 
#define inf 0x7fffffff/2;
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int a[11],k,n;
inline bool check(int x)
{
    while(x)
    {
        if(a[x%10])return 0;
        x/=10;
    }
    return 1;
}
int main(){
    n=read(),k=read();
    for(int i=1;i<=k;i++)
        a[read()]=1;
    int maxn=max(10000,10*n);
    for(int i=n;i<=maxn;i++)
    {
        if(check(i))
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().split())

ans=A*X+B*Y
for i in range(1,max(X,Y)+1):
  if i<=X and i<=Y:
    val=A*(X-i)+B*(Y-i)+C*2*i
    ans=min(ans,val)
  elif i>X:
    val=B*(Y-i)+C*2*i
    ans=min(ans,val)
  else:
    val=A*(X-i)+C*2*i
    ans=min(ans,val)
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include<math.h>
#include<stdio.h>
#include<utility>
#include<algorithm>

int main() {
	int H, W, n, m;
	n = 1;
	m = 1;
	while (true) {
		scanf("%d %d", &H, &W);

		if (H + W == 0) {
			break;
		}
		else {
			while (m <= H) {
				if (m == 1) {
					while (n <= W) {
						printf("#");
						n++;
					}
				}
				else if (m == H) {
					while (n <= W) {
						printf("#");
						n++;
					}
				}
				else {
					while (n <= W) {
						if (n == 1) {
							printf("#");
						}
						else if (n == W) {
							printf("#");
						}
						else {
							printf(".");
						}
						n++;
					}
				}
				printf("\n");
				n = 1;
				m++;
			}
			printf("\n");
			n = 1;
			m = 1;
			H = 0;
			W = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2512
from collections import defaultdict as dd
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
m = dd(int)
m1 = dd(int)

m['r']='p'
m['p']='s'
m['s']='r'

m1['r']=p
m1['p']=s
m1['s']=r
res=0
for i in range(k):
	res+=m1[t[i]]
	t = t[:i]+m[t[i]]+t[i+1:]
	
	
#print(res)
	
for i in range(k,n):
	#lose
	#print(t)
	if t[i-k] == m[t[i]]:
		t = t[:i]+'x'+t[i+1:]
		#print(t)
	else:
		res+=m1[t[i]]
		t = t[:i]+m[t[i]]+t[i+1:]
	#print(res)	
print(res)
	

Measured memory_bytes: 3748
#include <stdio.h>
struct binary_tree{
    int n;
    int l;
    int r;
};
binary_tree bt[1000000];
int now=0;
void push(int n,int t){
    if(now==0){
        bt[0].n=n;
        now++;
        return;
    }
    if(bt[t].n<n){
        if(bt[t].r==0){
            bt[t].r=now;
            bt[bt[t].r].n=n;
            now++;
        }
        else push(n,bt[t].r);
    }
    if(bt[t].n>n){
        if(bt[t].l==0){
            bt[t].l=now;
            bt[bt[t].l].n=n;
            now++;
        }
        else push(n,bt[t].l);
    }
}
void dfs(int n){
    printf(" %d",bt[n].n);
    if(bt[n].l!=0){
        dfs(bt[n].l);
    }
    if(bt[n].r!=0){
        dfs(bt[n].r);
    }
}
void print_sorted(int n){
    if(bt[n].l!=0){
        print_sorted(bt[n].l);
    }
    printf(" %d",bt[n].n);
    if(bt[n].r!=0){
        print_sorted(bt[n].r);
    }
}
int main(){
    int n,temp;
    char a[1000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        bt[i].n=bt[i].l=bt[i].r=0;
        scanf("%s",a);
        if(a[0]=='i'){
            scanf("%d",&temp);
            push(temp,0);
        }
        if(a[0]=='p'){
            print_sorted(0);
            printf("\n");
            dfs(0);
            printf("\n");
        }
    }
}



Measured memory_bytes: 8436
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	double a[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	sort(a, a + 5);
	cout << a[4] << " ";
	cout << a[3] << " ";
	cout << a[2] << " ";
	cout << a[1] << " ";
	cout << a[0] << endl;;

	return 0;
}

Measured memory_bytes: 3260
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	string s;
	cin >> s;
	if(s.l_ength()==3){
		swap(s[0],s[2]);
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
def solve():
    x = raw_input()
    y = raw_input()
    a, b = len(x), len(y)
    x1 = [0 for k in range(b+1)]
    for i in xrange(a):
        c = x[i]
        x2 = x1+[]
        for j in xrange(b):
            if c == y[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    print max(x1)
  
n = input()
for i in xrange(n):
    solve()

Measured memory_bytes: 6476
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<vector<int64_t>>A(N,vector<int64_t>(31));
  for(int i=0;i<N;i++){
  int64_t a; cin>>a;
    for(int j=0;j<31;j++){
    if(a%2==0)
      A[i][j]=0;
      else
        A[i][j]=1;
      a/=2;
    }
  }for(int j=0;j<31;j++){
    int64_t sum=0;
      for(int i=0;i<N;i++)
        sum+=A[i][j];
      if(sum%2==1){
      for(int k=0;k<N;k++)
        if(A[k][j]==1)
          A[k][j]=0;
        else
          A[k][j]=1;
      }
        }
  vector<int64_t>B(N);
    for(int i=0;i<N;i++){
    int64_t a=0;
      for(int j=0;j<31;j++){
      int64_t p=pow(2,j);
        a+=A[i][j]*p;
      
      }B[i]=a;
    
    }for(int i=0;i<N-1;i++)
      cout<<B.at(i)<<" ";
    cout<<B.at(N-1)<<endl;
 
  return 0;
}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, k ;
    cin>> n >> k ;
    vi h(n+1), dp(n+1, inf) ;
    for(int i=1 ; i<=n ; i++) cin>> h[i] ;
    dp[1]=0 ;
    for(int i=2 ; i<=n ; i++)
      for(int j=1 ; j<=k ; j++)
        if(i-j>=0)
          dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j])) ;
    cout<< dp[n] ;
  }


Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	stack<int> s1;
	stack< pair<int,int> > s2;
	vector<int> miz;
	string str;
	cin >> str;

	int sum = 0;
	for (int i = 0; i < str.length(); i++) {
		;
		if (str[i] == '\\') 
		{
			s1.push(i);
		}
		else if(str[i] == '/')
		{
			if (s1.empty()) {
				continue;
			}
			int a = s1.top();
			s1.pop();
			sum += (i - a);
			int b = i - a;
			while ((!s2.empty()) && (s2.top().first > a))
			{
				b += s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(a, b));
		}
	}
	
	vector<int> ans;
	while (!s2.empty())
	{
		ans.push_back(s2.top().second);
		s2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

struct Combination {
	const int MAX = 5000010;
	const int MOD;
	vector<fint64> FAC;
	vector<fint64> INV;
	vector<fint64> FAC_INV;
	Combination(fint64 MOD) :
		MOD(MOD),
		FAC(vector<fint64>(MAX)),
		INV(vector<fint64>(MAX)),
		FAC_INV(vector<fint64>(MAX))
		{
			FAC[0] = INV[1] = FAC_INV[0] = 1;
			for(int i = 1; i < MAX; ++i) {
				FAC[i] = FAC[i - 1] * i % MOD;
				if(i > 1) INV[i] = MOD - INV[MOD % i] * (MOD / i) % MOD;
				FAC_INV[i] = FAC_INV[i - 1] * INV[i] % MOD;
			}
		}
	fint64 C(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[r] % MOD * FAC_INV[n - r] % MOD;
	}
	fint64 P(int n, int r) {
		if(n < 0 or r < 0 or n < r) return 0;
		return FAC[n] * FAC_INV[n - r] % MOD;
	}
	fint64 H(int n, int r) {
		if(r == 0) return 1;
		return C(n + r - 1, r);
	}
};

using mint = ModInt<MOD>;
int main() {
	Combination com(MOD);
	int n, k; cin >> n >> k;
	vector<int> _(n); rep(i,n) cin >> _[i];
	sort(all(_));
	mint a[n]; rep(i,n) a[i] = _[i];

	mint maxi, mini;
	for(int i = 0; i < n; ++i) {
		if(i >= k - 1) {
			mint M = com.C(i, k - 1);
			M *= a[i];
			maxi += M;
		}
		if(n - 1 - i >= k - 1) {
			mint m = com.C(n - 1 - i, k - 1);
			m *= a[i];
			mini += m;
		}
	}
	cout << maxi - mini << '\n';
	return 0;
}

Measured memory_bytes: 118656
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define gcd(m,n)        __gcd(m,n)
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz               size()
#define inc(i,x,y)      for(int i=x;i<=y;i++)
#define dec(i,x,y)      for(int i=x;i>=y;i--)



#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}

//////////////////////////////code//////////////////////////////

pii ispossible(int a,int n)
{
    int r = a*a*a*a*a-n;
    int l=0,h=5000;
    int f=0;
    if(r<0)
    {
        f=1;
        r = abs(r);
    }
    int b;
    while(l<=h)
    {
        int m = (l+h)/2;
       //deb(l,m,h,r);
        if(m*m*m*m*m<=r)
        {
            b=m;
            l=m+1;
        }
        else
            h=m-1;
    }
      pii p;
    if(b*b*b*b*b==r)
    {
      p.ff=1;
      p.ss=b;
      if(f)
        p.ss=-p.ss;
    }
    else
    {
        p.ff=0;
    }

    return p;


}

int32_t main()
{
  fast();

  int n;
  cin>>n;

  int i=0;
  while(i*i*i*i*i<=1e18)
  {
     pii p =  ispossible(i,n);

     if(p.ff)
     {
         cout<<i<<" " <<p.ss;
         return 0;
     }
     i++;
  }


}


Measured memory_bytes: 3568
#include <stdio.h>

int main(int argc, const char * argv[]) {

    int a;
    int b;
    
    scanf("%d %d",&a,&b);
    if (a>b) {
        printf("a > b\n");
    }else if (a<b){
        printf("a < b\n");
    }else if(a==b){
        printf("a == b\n");
    }
    
    
    return 0;
    
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
const int N=1e5+5;
int to[N],Next[N],last[N],a[N],b[N],n,m,id[N],edge,x,y,f[N],vis[N];
long long sum[N],dp[N];
std::vector<int> e[N];
bool cmp(int x,int y){
	return a[x]<a[y];
}
void add(int x,int y){
	to[++edge]=y;
	Next[edge]=last[x];
	last[x]=edge;
}
void dfs(int x){
	sum[x]=b[x];
	for (int i=last[x];i;i=Next[i]){
		int u=to[i];
		dfs(u);	
		sum[x]+=sum[u];
	}
}
void Dfs(int x){
	dp[x]=a[x]+sum[x];
	for (int i=last[x];i;i=Next[i]){
		int u=to[i];
		Dfs(u);
		dp[x]=std::min(dp[x],std::max(a[x]*1ll,dp[u])+sum[x]-sum[u]);
	}
}
int find(int x){
	if (f[x]==x) return x;
	f[x]=find(f[x]);
	return f[x];
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]=std::max(a[i]-b[i],0);
	}
	for (int i=1;i<=n;i++) id[i]=i;
	std::sort(id+1,id+n+1,cmp);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		e[x].push_back(y),e[y].push_back(x);	
	}
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n;i++){
		int x=id[i];
		vis[x]=1;
		for (auto j:e[x])
			if (vis[j]==1){
				int ff=find(j);
				if (ff!=x) add(x,ff),f[ff]=x;
			}
	}
	dfs(id[n]);	
	Dfs(id[n]);
	printf("%lld\n",dp[id[n]]);
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s;cin>>s;
  vi a(4);
  rep(i,4){
    a[i]=s[i]-'0';
  }
  rep(i,2){
    int b;
    if(i)b=-a[1];
    else b=a[1];
    rep(j,2){
      int c;
      if(j)c=-a[2];
      else c=a[2];
      rep(k,2){
        int d;
        if(k)d=-a[3];
        else d=a[3];
        int res=a[0]+b+c+d;
        if(res==7){
          string ans=to_string(a[0]);
          if(i)ans+="-";
          else ans+="+";
          ans+=to_string(a[1]);
          if(j)ans+="-";
          else ans+="+";
          ans+=to_string(a[2]);
          if(k)ans+="-";
          else ans+="+";
          ans+=to_string(a[3])+"=7";
          cout<<ans<<endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char S[2000020];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(S, 1, 2000020, stdin);

	char* c = S, ct;
	int N = 0;
	
	while ((ct = *c++) >= '0') N = N * 10 + ct - '0';

	int L = 0, R = 2000001;
	while (L + 1 < R) {
		int M = (L + R) / 2;
		if (*(c + M) >= ' ') L = M;
		else R = M;
	}

	if (*c == '0') {
		printf("0\n");
		return 0;
	}

	int zero = 0;
	int n = R / 8 + 1;
	for (char* d = c; d < c + R - 8; d += 7) {
		ll tmp = *(ll*)(d);
		tmp += 0x1010101010101010;
		tmp ^= 0xcfcfcfcfcfcfcfcf;

		ll tmp2 = tmp + 0x0001000100010001;
		if ((tmp2 << 1 ^ tmp2) & 0x2000200020002000) {
			printf("0\n");
			return 0;
		}
		tmp2 = tmp + 0x0000010001000100;
		if ((tmp2 << 1 ^ tmp2) & 0x0020002000200000) {
			printf("0\n");
			return 0;
		}
	}

	for (char* d = c + min(0, R - 10); d < c + R; d++) {
		if (*d == ' ' && *(d + 1) == '0') {
			printf("0\n");
			return 0;
		}
	}

	if (R >= N * 2 + 18) {
		printf("-1\n");
		return 0;
	}

	ll kotae = 1;
	auto owa = c + R;
	while (c < owa) {
		ll tmp = *(ll*)(c);
		if (tmp != 0x2031203120312031) {
			ll k = 0;
			while ((ct = *c++) >= '0') k = k * 10 + ct - '0';
			if (ll(1e18) / kotae < k) {
				printf("-1\n");
				return 0;
			}
			else kotae *= k;
		}
		else c += 8;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3340