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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e18;
const double PI = acos(-1);

P readP() {
    double x, y;
    cin >> x >> y;
    return P(x, y);
}

struct C {
    P p;
    double r;
    C(){}
    C(P _p, double _r) : p(_p), r(_r) {}
    C(double _x, double _y, double _r) : p(_x, _y), r(_r) {}
    void print() {
        cerr << p.real() << " " << p.imag() << " " << r << endl;
    }
};

C readC() {
    double x, y, r;
    cin >> x >> y >> r;
    return C(x, y, r);
}

double distanceCC(C c1, C c2) {
    double d = abs(c1.p - c2.p);
    return max(0., d - (c1.r + c2.r));
}

struct edge {
    int to;
    double cost;
    edge(){}
    edge(int _to, double _cost) : to(_to), cost(_cost) {}
};
typedef vector<vector<edge>> Graph;

// undirected
void addEdge(Graph& G, int x, int y, double c) {
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
}
double dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    using State = pair<double, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    vector<double> d(n, INF);
    d[s] = 0;
    pq.push(make_pair(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d[g];
}

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

    P s, g;
    s = readP();
    g = readP();
    int n;
    cin >> n;

    vector<C> vc;
    vc.emplace_back(s, 0);
    rep2(i, 1, n + 1) {
        vc.emplace_back(readC());
    }
    vc.emplace_back(g, 0);

    Graph G(n + 2);
    rep(i, n + 2) {
        rep2(j, i + 1, n + 2) {
            addEdge(G, i, j, distanceCC(vc[i], vc[j]));
        }
    }

    cout << fixed << setprecision(10) << dijkstra(G, 0, n + 1) << endl;
}


Measured memory_bytes: 20720
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    int h,w;
    cin >> h >> w;
    //VVI a(h,VI(w));
    vector<vector<char>> a(h,vector<char>(w));
    VI cnt(26,0);
    REP(i,0,h) REP(j,0,w) {
        cin >> a[i][j];
        cnt[a[i][j] - 'a']++;
    }
    //int speh = h % 2 == 0 ? -1 : h/2;
    //int spew = w % 2 == 0 ? -1 : w/2;
    if (h % 2 == 0 && w % 2 == 0) {
        REP(i,0,26) {
            //cerr << cnt[i] << endl;
            if (cnt[i] % 4 != 0) {
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }
    if (h % 2 == 1 && w % 2 == 1) {
        int c2 = h + w - 2;
        int c[4] = {};
        REP(i,0,26) {
            if (cnt[i] >= 4) {
                c[2] += cnt[i] / 4;
                cnt[i] %= 4;
            }
            if (cnt[i] == 0) ++c[3];
            else if (cnt[i] % 2 == 0) ++c[1];
            else if (cnt[i] == 1) ++c[0];
        }
        if (c[1] < c2/2) {
            c[1] == c2 / 2;
            c[2] -= (c2 / 2 - c[1] + 1) / 2;
        }
        if (c[0] == 1 && c[2] == (h * w - c2 - 1) / 4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    if (h % 2 == 1 && w % 2 == 0) swap(h,w);
    if (h % 2 == 0 && w % 2 == 1) {
        int c2 = h;
        int c[2] = {};
        REP(i,0,26) {
            //cerr << cnt[i] << endl;
            if (cnt[i] >= 4) {
                c[1] += cnt[i] / 4;
                cnt[i] = cnt[i] % 4;
            }
            if (cnt[i] % 2 == 0 && cnt[i]) c[0]++;
            //cerr << c[0] << "," << c[1] << "," << cnt[i] << endl;
        }
        //cerr << c[0] << "," << c[1] << endl;
        if (c[0] < c2/2) {
            c[1] -= (c2 / 2 - c[0] + 1) / 2;
        }
        if (c[1] == (h * w - h) / 4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
D = {}
for i in A :
    if i in D :
        D[i] += 1
    else :
        D[i] = 1
KEY = list(D.keys())
ITEM = list(D.values())
ans = 0
for i in range(len(KEY)) :
    if KEY[i] <= ITEM[i] :
        ans += ITEM[i]-KEY[i]
    else :
        ans += ITEM[i]
print(ans)


Measured memory_bytes: 18160
// AOJ ALDS1_8_A: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_A
// AOJ ALDS1_8_B: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_B
// AOJ ALDS1_8_C: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_C

package main

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

type node struct {
	key                 int
	parent, left, right *node
}

var root *node
var sc = bufio.NewScanner(os.Stdin)

func insert(key int) {
	var y *node
	x := root

	z := &node{key, nil, nil, nil}

	for 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
		}
	}
}

func find(key int) *node {
	// start root node
	x := root
	for x != nil {
		// find key
		if x.key == key {
			return x
		}

		// move node
		if x.key > key {
			x = x.left
		} else {
			x = x.right
		}
	}
	return nil
}

func delete(n *node) {

	// 削除対象のnodeをyとする
	// nodeに子がない場合または子が1つの場合はnodeを削除対象にする
	// 子が2つある場合はnodeの次節点を削除対象にする
	var y *node
	if n.left == nil || n.right == nil {
		y = n
	} else {
		y = getSuccessor(n)
	}

	// yの子xを決める
	var x *node
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}

	if x != nil {
		x.parent = y.parent // xの親を設定
	}

	if y.parent == nil {
		root = x // yがrootのとき、xをrootに設定する
	} else if y == y.parent.left {
		y.parent.left = x // yがyの親の左の子なら、xをyの親の左の子として設定する
	} else {
		y.parent.right = x // yがyの親の右の子なら、xをyの親の右の子として設定する
	}

	if y != n {			// nの次節点が削除された場合
		n.key = y.key	// yのkeyをnにコピーする
	}
}

func getSuccessor(n *node) *node {
	if n.right != nil {
		return getMinimum(n.right)
	}

	y := n.parent
	for y != nil && n == y.right {
		n = y
		y = n.parent
	}
	return y
}

func getMinimum(x *node) *node {
	for x.left != nil {
		x = x.left
	}
	return x
}

func inorder(u *node, list []int) []int {
	if u != nil {
		list = inorder(u.left, list)
		// fmt.Printf(" %v", u.key)
		list = append(list, u.key)
		list = inorder(u.right, list)
	}
	return list
}

func preorder(u *node, list []int) []int {
	if u != nil {
		// fmt.Printf(" %v", u.key)
		list = append(list, u.key)
		list = preorder(u.left, list)
		list = preorder(u.right, list)
	}
	return list
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

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

func nextInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	var command string
	var n, key int

	fmt.Scanf("%d", &n)

	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		command = nextString()
		switch command {
		case "insert":
			key = nextInt()
			insert(key)
		case "find":
			key = nextInt()
			if exist := find(key); exist != nil {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		case "delete":
			key = nextInt()
			if node := find(key); node != nil {
				delete(node)
			}
		case "print":
			printList(inorder(root, []int{}))
			printList(preorder(root, []int{}))
		}
	}
}


Measured memory_bytes: 40276
function main(input){
    let numarray=input.split(' ').map(Number);
    numarray.sort();
    let a,b,c;
    a=numarray[0];
    b=numarray[1];
    c=numarray[2];
    console.log(a + ' ' + b + ' ' + c);
}
main(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 15164
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	//删除最后一个字符的方法
	//1.substr
	//b=b.substr(0,b.size()-1);
	//2.erase函数
	//b.erase(b.end()-1); 
	//3.pop_back函数
	b.pop_back(); 
	cout<<(a==b?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
const int size=(1<<12);
const int inf=1e9;
int dp[size];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=0;i<size;i++)
        dp[i] = inf;
    int n,m;
    cin>>n>>m;
    int limit = (1<<n);
    vector <pi> v;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        int mask = 0;
        for(int j=0,x;j<b;j++)
        {
            cin>>x;
            x--;
            mask |= (1<<x);
        }
        v.push_back({a,mask});
    }
//    for(int i=0;i<m;i++)
//        cout<<v[i].second<<endl;
    dp[0]=0;
    for(int mask=0;mask<limit;mask++)
    {
        for(int i=0;i<v.size();i++)
        {
            int new_mask = mask|v[i].second;
            dp[new_mask] = min(dp[new_mask],dp[mask]+v[i].first);
        }
    }
//    for(int i=0;i<limit;i++)
//        cout<<dp[i]<<endl;
    if(dp[limit-1]==inf)
        return cout<<"-1\n",0;
    cout<<dp[limit-1]<<"\n";
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int o;
  int c;
};

bool cmp1(T a, T b) {
  return a.c < b.c;
}

bool cmp2(T a, T b) {
  return a.o > b.o;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int o = 0, c = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        o++;
      } else {
        if (o) {
          o--;
        } else {
          c++;
        }
      }
    }
    if (o >= c) {
      a.push_back({o, c});
    } else {
      b.push_back({o, c});
    }
    sumtop += o - c;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur - it.c < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o - it.c;
  }
  for (auto &it : b) {
    if (cur - it.c < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o - it.c;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 11224
#include <iostream>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

const string YES = "Yes";
const string NO = "No";

void solve(string S) {
  bool pred = S.find('A') != S.npos && S.find('B') != S.npos;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;

vector<i64> X,Y;

int main() {
  cin >> N;
  X.resize(N);
  Y.resize(N);
  for(int i = 0;i < N;i++) {
    cin >> X[i] >> Y[i];
  }
  vector<i64> vec;

  {
    i64 aa = (abs(X[0]) + abs(Y[0])) % 2;
    if(aa == 0) vec.push_back(1);
    for(int i = 0;i < N;i++) {
      if(aa != (abs(X[i]) + abs(Y[i])) % 2) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  for(int i = 0;i < 39;i++) {
    vec.push_back((1LL << i));
  } 
  cout << vec.size() << endl;
  for(int i = 0;i < vec.size();i++) {
    cout << vec[i] << " \n"[i + 1 == vec.size()];
  }

  for(int i = 0;i < N;i++) {
    vector<char> ss(vec.size());
    i64 x = X[i] + Y[i];
    i64 y = X[i] - Y[i];
    for(int i = vec.size() - 1;i >= 0;i--) {
      i64 d = vec[i];
      bool xp = false, yp = false;
      if(0 <= x) xp = true, x -= d;
      else x += d;
      if(0 <= y) yp = true, y -= d;
      else y += d;
      if(xp && yp) ss[i] = 'R';
      if(!xp && yp) ss[i] = 'D';
      if(!xp && !yp) ss[i] = 'L';
      if(xp && !yp) ss[i] = 'U';
    }
    for(auto c: ss) {
      cout << c;
    }
    cout << endl;
  }

}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int n, k;
    cin >> n >> k;

    int A[n];

    for(int i = 0; i < n; i++) cin >> A[i];

    sort(A, A + n);

    int tot =0;
    for(int i = 0; i < k ;i++) tot += A[i];

    cout << tot;
}









Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
// jlkjflskjdflj
#define SIZE 200000
 
 
using namespace std;
 
int main() {
    unsigned long long int A,B,C,D,i,j,k,N,M,K,Q,X,dix;
  //  long long int A[100][100];
 
 cin >> N;
 
 dix = 1;
 for (i=1;i<=9;i++)
  dix *= 10;
 dix *= dix;
 
 cin >> A;
 long encore;
 encore = 1;
 for (i=2;i<=N;i++) {
   cin >> B;
   if ((A == 0) || (B == 0)) {
     A = 0;
     encore = 1;
   }
   else if (encore) {
     C = A*B;
     if (C <= dix) {
         if (C/B == A) {
           A = C;
         }
         else encore = 0;
     }
     else {
       encore = 0;
     }
   }
 }
if ((encore) || (A == 0))
  cout << A << endl;
else
  cout << "-1" << endl;
 
  return 0;
 
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;

const int N=100005;

struct E{
	int to,next;
}mem[N<<1];
int n,num,x,cnt;
int dp[N],head[N],son[N];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

bool cmp(int a,int b){
	return dp[a]<dp[b];
}

void dfs(int k,int pre){
	int j,u;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs(u,k);
	}
	cnt=0;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		son[++cnt]=u;
	}
	sort(son+1,son+1+cnt,cmp);
	for (j=1;j<=cnt;j++) dp[k]=max(dp[k],dp[son[j]]+cnt-j+1);
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=2;i<=n;i++){
		scanf("%d",&x);
		add(i,x); add(x,i);
	}
	dfs(1,0);
	printf("%d\n",dp[1]);
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>

//数字として比較すると入りきらない

using namespace std;

int main(void) {
	string s, t;
	cin >> s >> t;
	if (s.size() > t.size()) {
		cout << "GREATER";
	}
	else if (s.size() < t.size()) {
		cout << "LESS";
	}
	else {
		for (long long i = 0; i < s.size(); i++) {
			if (s[i] > t[i]) {
				cout << "GREATER";
				break;
			}
			else if (s[i] < t[i]) {
				cout << "LESS";
				break;
			}
			else {
				cout << "EQUAL";
				break;
			}
		}
	}
	return 0;
}

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

struct state{
	Long len, link;
	map<char,int> next;
	state(){}
	state(Long len, Long link) : len(len), link(link){}
};

struct suffixAutomaton{
	vector<state> st;
	Long sz, last;
	
	suffixAutomaton(){}
	suffixAutomaton(Long n){
		st.resize(n << 1ll);
		last = 0;
		st[0].len = 0;
		st[0].link = -1;
		sz = 1;
	}
	
	void addChar(char c){
		Long cur = sz++;
		st[cur].len = st[last].len + 1;
		Long p = last;
		while(p != -1 && !st[p].next.count(c)){
			st[p].next[c] = cur;
			p = st[p].link;
		}
		if(p == -1){
			st[cur].link = 0;
		}else{
			Long q = st[p].next[c];
			if(st[p].len + 1 == st[q].len){
				st[cur].link = q;
			}else{
				Long clone = sz++;
				st[clone].len = st[p].len + 1;
				st[clone].next = st[q].next;
				st[clone].link = st[q].link;
				while(p != -1 && st[p].next[c] == q){
					st[p].next[c] = clone;
					p = st[p].link;
				}
				st[q].link = st[cur].link = clone;
			}
		}
		last = cur;
	}
	
	void build(string &s){
		for(char c : s) addChar(c);
		return;
	}
};


const Long MX = 1e4 + 10;
suffixAutomaton sa;
Long memo[MX];
bool used[MX];
bool ok;
string ans;

Long dp(Long u){
	if(used[u]) return memo[u];
	used[u] = true;
	memo[u] = 1;
	for(auto par : sa.st[u].next){
		memo[u] += dp(par.second);
	}
	return memo[u];
}

void reconstruct(Long u, Long l, Long r, Long k){
	if(l == k){
		ok = true;
		return;
	}
	Long aux = 1;
	for(auto par : sa.st[u].next){
		Long v = par.second;
		if(l + aux <= k && k <= l + aux + memo[v] - 1){
			reconstruct(v, l + aux, l + aux + memo[v] - 1, k);
			if(ok){
				ans += par.first;
				break;
			}
		}
		aux += memo[v];
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	string s;
	cin >> s;
	Long k;
	cin >> k;
	k++;
	
	sa = suffixAutomaton(s.size());
	sa.build(s);
	dp(0);
	ok = false;
	ans = "";
	reconstruct(0,1,memo[0],k);
	reverse(ans.begin(),ans.end());
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1664
from collections import Counter
import sys

sys.setrecursionlimit(10**6)


N = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret

st = SegmentTree([0]*2*(10**5), max, 0)

for h, a, i in sorted(zip(H, A, range(N))):
    st.update(i, st.query(0, i) + a)

print(st.query(0, N))


Measured memory_bytes: 121680
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let x = line[0];

    let mut ans = 0;
    let mut tmp = 100;
    while tmp < x {
        tmp += tmp / 100;
        ans += 1;
    }

    println!("{}", ans);
}


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

int dp[20],in[20],ans[111],t,id;
queue<int>q;

void dele(){
  r(i,17)if(dp[i]!=-1){
    int x=17*(dp[i]%2)+3*(dp[i]%3)+19;
    if(in[i]+x<=t)dp[i]=-1;
  }
}

void inse(){
  while(!q.empty()){
    int x=q.front();
    int n,flag=0;;
    if(x%5==1)n=5;
    else n=2;
    r(i,17)if(dp[i]==-1){
      if(i+n>17)continue;
      int f=0;
      r(j,n)if(dp[i+j]!=-1)f=1;
      if(f)continue;
      r(j,n){
        in[i+j]=t;
        dp[i+j]=x;
        flag++;
      }
      ans[x]=t-5*x;
      break;
    }
    if(flag)q.pop();
    else break;
  }
}

int main(){
  memset(dp,-1,sizeof(dp));
  for(t=0;t<1000000;t++){
    if(t%5==0&&id<=100)q.push(id++);
    dele();
    inse();
  }
  int n;
  while(cin>>n)cout<<ans[n]<<endl;
}


Measured memory_bytes: 2980
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	string s;
	string t;
	char c='a';
	int n;
	int cnt[26];
	int ans=99999;
	
	cin>>s;
	fill(cnt,cnt+26,0);
	n=s.length();
	for(int i=0;i<n;i++)
		cnt[s[i]-'a']++;
	for(int i=0;i<26;i++)
	{
		t=s;
		int cc=0;
		if(cnt[i]>0)
		{
			c=i+'a';
			bool f=true;
			while(1)
			{
				f=true;
				for(int i=0;i<t.length();i++)
				{
					if(t[i]!=c)
					{
						f=false;
						break;
					}
				}
				if(f)
				{
					break;
				}else{
					cc++;
					for(int i=0;i<t.length()-1;i++)
					{
						if(t[i]==c ||t[i+1]==c)
							t[i]=c;
					}
					t.pop_back();
				}
			}
			if(ans>cc)
				ans=cc;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	char ch;

	cin >> ch;

	if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;

	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 1010
const int MOD = 1000000007;


int dist[maxn][maxn];
vector<string> v;
int h, w;
int ch, cw;
int dh, dw;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};

bool valid(pair<int, int> a) {
    return !(a.first < 0 or a.second < 0 or a.first >= h or a.second >= w);
}


void dijkstra() {
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<>> st;
    dist[ch][cw] = 0;
    st.push({0, {ch, cw}});
    while (!st.empty()) {
        auto top = st.top();
        st.pop();

        int node_dist = top.first;
        auto node = top.second;

        if (node_dist != dist[node.first][node.second])continue;

        for (int i = 0; i < 4; i++) {
            pair<int, int> tp = {node.first + dx[i], node.second + dy[i]};
            if (valid({tp.first, tp.second}) and v[tp.first][tp.second] == '.') {
                if (dist[tp.first][tp.second] > node_dist) {
                    dist[tp.first][tp.second] = node_dist;
                    st.push({dist[tp.first][tp.second], {tp.first, tp.second}});
                }
            }
        }
        for (int i = -2; i <= 2; i++)
            for (int j = -2; j <= 2; j++) {
                if (i == 0 and j == 0)continue;
                pair<int, int> tp = {node.first + i, node.second + j};
                if (valid({tp.first, tp.second}) and v[tp.first][tp.second] == '.') {
                    if (dist[tp.first][tp.second] > 1 + node_dist) {
                        dist[tp.first][tp.second] = 1 + node_dist;
                        st.push({dist[tp.first][tp.second], {tp.first, tp.second}});
                    }
                }
            }
    }
}


void solve() {
    cin >> h >> w;

    cin >> ch >> cw;
    ch--, cw--;
    cin >> dh >> dw;
    dh--, dw--;

    v = vector<string>(h);
    for (int i = 0; i < h; i++)cin >> v[i];
    memset(dist, 63, sizeof dist);
    dijkstra();
    if (dist[dh][dw] > INT_MAX)cout << -1;
    else cout << dist[dh][dw];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 12812
#include <stdio.h>
void bubbleSort(int *A,int N,int *x){
    int flag = 1,t,i;
    while(flag){
        flag = 0;
        i = 0;
        for(int j = N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                t = A[j]; A[j] = A[j-1]; A[j-1] = t;
                flag = 1;
                *x = *x + 1;
            }
        }
        i++;
    }
}
void show(int *a,int n) {
    for (int i = 0; i < n; i++)
    {
        /* code */
        if(i != n-1){
            printf("%d ",a[i]);
        }else{
            printf("%d\n",a[i]);
        }
    }
    
}
int main(){
    int A[100];
    int n;
    int c = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    bubbleSort(A,n,&c);
    show(A,n);
    printf("%d\n",c);


}


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

int main() {

	int n; cin >> n;
	vector<ll> a(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<int> ball(n + 1, 0);
	ll cnt = 0;
	for (int i = n; i >= 1; i--) {
		ll tmp = 0;
		for (int j = i + i; j <= n; j += i) {			
			tmp += ball[j];
		}
		if (tmp % 2 != a[i]) {
			ball[i] = 1;
			cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= n; i++) {
		if (ball[i] == 1) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 5540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  
  bool can_finish = false;
  int count = 0;
  int next = 1;
  while (can_finish != true)
  {
    if (count >= N)
    {
    	count = -1;
      	break;
    }
  	if (a.at(next-1) == 2) can_finish = true;
    count++;
    next = a.at(next-1);
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  vi a(n); rep(i, n) cin >> a[i];

  int query; cin >> query;

  for (int i = 0; i < query; ++i) {
    int b, e; cin >> b >> e;
    reverse(a.begin() + b, a.begin() + e);
  }

  assert(a.size() == n);

  for (size_t i = 0; i < a.size(); ++i) {
    cout << a[i];
    if (i != n - 1) cout << " ";
  }
  cout << endl;

  return 0;
}


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

long long f(string s, int k) {
  int n = s.length();
  if (n < k) return 0;
  if (s[0] == '0') return f(s.substr(1), k);

  if (k == 1)
    return s[0] - '0' + 9 * (n - 1);
  
  long long res = f(s.substr(1), k - 1);
  if (k == 2)
    res += (s[0] - '1') * 9 * (n - 1) + 81 * (n - 1) * (n - 2) / 2;
  else
    res += (s[0] - '1') * 81 * (n - 1) * (n - 2) / 2 + 243 * (n - 1) * (n - 2) * (n - 3) / 2;
  return res;
}

int main() {
  string s;
  cin >> s;
  int k;
  scanf("%d", &k);

  long long ans = f(s, k);
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 256
<?php

$numData = trim(fgets(STDIN));
$count = 0;

while($count < $numData) {
	$data = explode(' ', trim(fgets(STDIN)));
	echo (isRightTriangle($data) ? "YES" : "NO") . "\n";
	$count++;
}

function isRightTriangle($data) {
	sort($data);
	list($a, $b, $c) = $data;
	return $a * $a + $b * $b == $c * $c;
}

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

int gcd( int m, int n ){
	if ((0 == m)||(0 == n))
		return 0;
	while(m != n){
		if(m > n) m = m - n;
		else      n = n - m;
	}
	return m;
};

int main(int argc, const char * argv[])
{
    int n, m;
    while(cin >> n >> m){
        cout << gcd(m, n) << "\n";
    }
    return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;

namespace arc081_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInt();
            var AL = GetIntList();
            var AD = new Dictionary<int, int>();
            foreach (var a in AL)
            {
                if (!AD.ContainsKey(a)) AD.Add(a, 0);
                AD[a]++;
            }

            var cl = AD.Where(x => x.Value >= 2).OrderByDescending(x => x.Key).ToList();

            if (cl.Count < 2)
                Console.WriteLine(0);
            else if(cl[0].Value >= 4)
                Console.WriteLine((long)cl[0].Key * (long)cl[0].Key);
            else
                Console.WriteLine((long)cl[0].Key * (long)cl[1].Key);

        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


Measured memory_bytes: 25568
/*
* ID: juryc
* PROG: Caracal vs monster
* LANG: C++
*/
long long recur(long long h){
if(h==1) return 1;
return 1+2*recur(h/2); 
}
#include<bits/stdc++.h>
using namespace std;
int main(){
long long h; cin>>h;
cout<<recur(h)<<"\n";
return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class LazySegmentTree {
  const int NONE = INT_MIN;
  int N;
  vector<int> lazy, dat;

  void setLazy(int k, int v){
    lazy[k] = v;
    dat[k] = v;
  }

  void push(int k){
    if(lazy[k] == NONE) return;
    setLazy(2*k+1, lazy[k]);
    setLazy(2*k+2, lazy[k]);
    lazy[k] = NONE;
  }
public:
  LazySegmentTree(int n){
    N = 1;
    while(N<n) N *= 2;
    dat.resize(2*N);
    lazy.resize(2*N);
    for(int i=0; i<2*N; i++){
      dat[i] = INT_MAX;
      lazy[i] = NONE;
    }
  }

  void update(int s, int t, int val){ update(s, t, val, 0, 0, N); }
  void update(int s, int t, int val, int k, int l, int r){
    if(r<=s || t<=l) return;
    if(s<=l && r<=t){
      setLazy(k, val);
      return;
    }
    push(k);
    update(s, t, val, 2*k+1, l, (l+r)/2);
    update(s, t, val, 2*k+2, (l+r)/2, r);
    dat[k] = min(dat[2*k+1], dat[2*k+2]);
  }

  int query(int s, int t){ return query(s, t, 0, 0, N); }
  int query(int s, int t, int k, int l, int r){
    if(r<=s || t<=l) return INT_MAX;
    if(s<=l && r<=t) return dat[k];
    push(k);
    int vl = query(s, t, 2*k+1, l, (l+r)/2);
    int vr = query(s, t, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
};

struct ST {
  int s, t, x;
};
bool operator<(const ST& a, const ST& b){
  return a.x > b.x;
}

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

  map<int,int> memo;
  vector<ST> v;
  rep(i,N){
    int s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;

    memo[s] = 1;
    memo[t] = 1;
    v.push_back((ST){s,t,x});
  }
  vector<int> w;
  rep(i,Q){
    int d;
    cin >> d;
    memo[d] = 1;
    w.push_back(d);
  }
  LazySegmentTree lst(1000000);
  map<int,int> zaatsu;
  int id = 0;
  FOR(it,memo){
    zaatsu[it->first] = id++;
  }

  sort(ALLOF(v));
  rep(i,v.size()){
    lst.update(zaatsu[v[i].s], zaatsu[v[i].t], v[i].x);
  }
  rep(i,w.size()){
    int x = zaatsu[w[i]];
    int res = lst.query(x, x+1);
    if(res == INT_MAX) cout << -1 << endl;
    else cout << res << endl;
  }
  
  
  return 0;
}




Measured memory_bytes: 76976
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll n;
ll a[100000];

int main(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    ll tmp = 0;
    ll psum = 0;
    for(int i=0;i<n;i++){
        tmp += a[i];
        if(i % 2 == 0){
            if(tmp <= 0){
                psum += (1 - tmp);
                tmp = 1;
            }
        }else{
            if(tmp >= 0){
                psum += (1 + tmp);
                tmp = -1;
            }
        }
    }
    tmp = 0;
    ll msum = 0;
    for(int i=0;i<n;i++){
        tmp += a[i];
        if(i % 2 != 0){
            if(tmp <= 0){
                msum += (1 - tmp);
                tmp = 1;
            }
        }else{
            if(tmp >= 0){
                msum += (1 + tmp);
                tmp = -1;
            }
        }
    }
    cout << min(psum,msum) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    int xy[n][2];
    rep(i, n) rep(j, 2) cin >> xy[i][j];

    int xy_cd[4][2];
    rep(i, 4) rep(j, 2) xy_cd[i][j] = xy[0][j];

    rep(i, n){
        if(xy[i][0] + xy[i][1] > xy_cd[0][0] + xy_cd[0][1]){
            rep(j, 2) xy_cd[0][j] = xy[i][j];
        }

        if(xy[i][0] - xy[i][1] > xy_cd[1][0] - xy_cd[1][1]){
            rep(j, 2) xy_cd[1][j] = xy[i][j];
        }

        if(-xy[i][0] + xy[i][1] > -xy_cd[2][0] + xy_cd[2][1]){
            rep(j, 2) xy_cd[2][j] = xy[i][j];
        }

        if(-xy[i][0] - xy[i][1] > -xy_cd[3][0] - xy_cd[3][1]){
            rep(j, 2) xy_cd[3][j] = xy[i][j];
        }
    }

    ll ans = 0;
    rep(i, 4){
        rep(j, n){
            ll d = (ll)abs(xy_cd[i][0] - xy[j][0]) + (ll)abs(xy_cd[i][1] - xy[j][1]);
            chmax(ans, d);
        }
    }

    pr(ans);
    return 0;}

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

using namespace std;

int main ()
{
	char s[3];
	scanf ("%s", s);
	int ans=0;
	for (int i=0; i<4; i++){
		if (s[i]==s[i+1]) ans=1;
	}
	if (ans==1) printf ("Bad");
	else printf ("Good");
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
max_val = 0
count = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
    else:
        max_val = max(max_val, count)
        count = 0
max_val = max(max_val, count)
print(max_val)

Measured memory_bytes: 85368
#include <iostream>
#include <algorithm>
using namespace std;
const int Maxn = 100100;
int G[Maxn];

int main(){
	int N,C,K;
	cin >> N >> C >> K;
	for( int i = 0; i < N; i++ ){
		cin >> G[i];
	}
	sort(G,G+N);
	int cnt = 0;
	int flag = 0;
	int total = 1;
	int index = G[0];
	for( int i = 0; i < N; i++ ){
		if( i == N-1 ){
			cnt++;
			break;
		}
		if( total < C and G[i+1]-index <= K ){
			total++;
		}else{
			index = G[i+1];
			total = 1;
			cnt++;
		}
	}
	cout << cnt << endl;
}


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


void solve(long long N, std::vector<long long> A){
    long long t[300000] = {};
    for (int i = 0; i < N-1; i++) {
        t[A[i]]++;
    }
    for (int i = 1; i <= N; i++) {
        cout << t[i] << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 7228
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(e,n,s) for(int i = e; i < n;i += s)
#define forr(e,n,s) for(int i = e; i >= n; i -= s)
#define PI 3.14159265358979323846264338327950L

using namespace std;

int MOD = 1e9+7;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout<<fixed;
  cout<<setprecision(20);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go(); 

    // code here
    string s,t;cin>>s>>t;
    int rowSize = s.length();
    int colSize = t.length();
    vector<vector<int>> dp(rowSize + 1,vector<int>(colSize + 1,0));
    for(int i = rowSize-1; i >= 0; i--){
        for(int j = colSize-1; j >= 0; j--){
            if(s[i]==t[j]){
                dp[i][j] = max(dp[i][j],1 + dp[i+1][j+1]);
            }
            dp[i][j] = max({dp[i][j],dp[i+1][j],dp[i][j+1]});
        }
    }
    int ans = dp[0][0];
    if(ans==0){
        cout<<""<<endl;
        return 0;
    }
    string sol = "";
    for(int i = 0; i < rowSize; i++){
        for(int j = 0; j < colSize; j++){
            if(ans==dp[i][j] and dp[i+1][j]==(ans-1) and dp[i][j+1]==(ans-1) and dp[i+1][j+1]==(ans-1)){
                   sol += s[i];
                   ans--;
                   break;
            }
        }
    }
    cout<<sol<<endl;
   
}





Measured memory_bytes: 38556
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

class AnalogClock():
  def __init__(self,h,m):
    self.h=h
    self.m=m
    self.SHDegree=30*h+m/2
    self.LHDegree=6*m

def main():
  a,b,h,m=LI()

  aclock=AnalogClock(h,m)

  x=aclock.SHDegree
  y=aclock.LHDegree
  sita=abs(x-y)
  if sita>180:
    sita=360-sita

  z=a*a+b*b-(2*a*b*math.cos(sita*math.pi/180))
  return math.sqrt(z)

# main()
print(main())


Measured memory_bytes: 11116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

const string YES = "Yes";
const string NO = "No";

int main(){
    ll h, w;
    cin >> h >> w;
    vector<ll> count(27);
    REP(i, h){
        string s;
        cin >> s;
        REP(j, w){
            count.at(s.at(j) - 'a')++;
        }
    }

    ll n4 = (h / 2) * (w / 2);
    ll n2 = (h / 2) * (w % 2) + (h % 2) * (w / 2);
    ll n1 = (h % 2) * (w % 2);

    assert(h * w == 4 * n4 + 2 * n2 + n1);

    // n4
    REP(i, count.size()){
        if(n4 > 0 && count.at(i) >= 4){
            ll m = count.at(i) / 4;
            n4 -= m;
            count.at(i) -= 4 * m;
        }
    }
    if(n4){
        cout << NO << endl;
        return 0;
    }

    // n2
    REP(i, count.size()){
        if(n2 > 0 && count.at(i) >= 2){
            ll m = count.at(i) / 2;
            n2 -= m;
            count.at(i) -= 2 * m;
        }
    }
    if(n2){
        cout << NO << endl;
        return 0;
    }

    // n1
    REP(i, count.size()){
        if(n1 > 0 && count.at(i) >= 1){
            n1--;
            count.at(i)--;
        }
    }
    if(n1){
        cout << NO << endl;
        return 0;
    }
    cout << YES << endl;
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
//const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

const ll INF = 1LL << 50;

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

    const int NMAX = 1000;
    const int MMAX = 2000;
    int a[MMAX], b[MMAX];
    ll c[MMAX];

    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    ll dist[NMAX];

    for(int i = 0; i < N; i++){
        dist[i] = INF;
    }

    dist[0] = 0;

    for(int loop = 0; loop < N - 1; loop++){
        for(int i = 0; i < M; i++){
            if(dist[a[i] - 1] == INF) continue;

            if(dist[b[i] - 1] > dist[a[i] - 1] + c[i]){
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
            }
        }
    }

    ll ans = dist[N - 1];

    bool negative[NMAX];

    for(int i = 0; i < N; i++){
        negative[i] = false;
    }

    for(int loop = 0; loop < N; loop++){
        for(int i = 0; i < M; i++){
            if(dist[a[i] - 1] == INF) continue;

            if(dist[b[i] - 1] > dist[a[i] - 1] + c[i]){
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
                negative[b[i] - 1] = true;
            }

            if(negative[a[i] - 1] == true){
                negative[b[i] - 1] = true;
            }
        }
    }

    if(negative[N - 1]){
        cout << "inf" << endl;
    }else{
        cout << -ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]

asum=sum(a) #当初の数列Aの要素の和
d={}

for i in a:
  if i in d:
    d[i]+=1
  else:
    d[i]=1

for b,c in bc:
  if b in d:
    asum+=d[b]*(c-b)
    if c in d:
      d[c]+=d[b]
    else:
      d[c]=d[b]
    d[b]=0
  print(asum)

Measured memory_bytes: 35828
H, W, K = map(int, input().split())
c = [input() for x in range(H)]
cnt = 0

for i in range(2 ** H - 1):
    for j in range(2 ** W - 1):
        sum = 0
        for ih in range(H):
            if 2 ** ih & i > 0:
                continue
            for iw in range(W):
                if 2 ** iw & j > 0:
                    continue
                if c[ih][iw] == '#':
                    sum += 1
        if sum == K:
            cnt += 1

print(cnt)


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

int main() {
  int N; cin >> N;
  int a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int S[N];
  int n = 1;
  for (int i = 0; i < N; i++) {
    S[i] = n;
    n = a[n-1];
    if (n == 2) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 1024