akhauriyash/Code-Regression huggingface dataset:
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

// #include <bits/extc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> // tree
// #include <ext/pb_ds/hash_policy.hpp> // hash
// #include <ext/pb_ds/trie_policy.hpp> // trie
// #include <ext/pb_ds/priority_queue.hpp> // priority_queue
// using namespace __gnu_pbds;

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

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define Push push_back

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

const lli mod = 1E9 + 7;
const Double PI = 3.1415926535846;
const Double eps = 1e-8;

lli fastPow(lli base, lli exp, lli module = mod) {
	lli ans = 1;
	base %= module;
	while (exp) {
		if (exp & 1) ans = ans * base % module;
		base = base * base % module;
		exp >>= 1;
	}
	return ans;
}

bool millerRabin(lli n, lli a) {
	/*
	 * n < 4,759,123,141		3 : {2, 7, 61}
	 * n < 1,122,004,669,633	4 : {2, 13, 23, 1662803}
	 * n < 3,474,749,660,383	6 : {p in [2, 13]}
	 * n < 2^64					7 : 
	 * {2, 325, 9375, 28178, 450775, 9780504, 1795265022}
	 *
	 * else, random everytime gives a 75% of correction
	 */
	
	if (n < 2) return 0;
	if ((a = a%n) == 0) return 1;
	if (n & 1 ^ 1) return n == 2;
	
	lli lowb = (n - 1) & -(n - 1);
	lli tmp = (n - 1) / lowb; // lowbit of (n-1)
	lli t = __lg(lowb);
	lli x = 1;
	
	for (; tmp; tmp /= 2, a = a*a%n) {
		if (tmp & 1) x = x * a % n;
	}
	
	if (x == 1 or x == n - 1) return 1;
	
	while (--t) {
		if ((x = x*x%n) == n - 1) return 1;
	}
	
	return 0;
}

bool MR_PrimeFilter(lli n) {
	vector<lli> v[4];
	v[0] = {2, 7, 61};
	v[1] = {2, 13, 23, 1662803};
	v[2] = {2, 3, 5, 7, 11, 13};
	v[3] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
	
	if (n < 4759123141LL) {
		for (lli x : v[0]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	if (n < 1122004669633LL) {
		for (lli x : v[1]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	if (n < 3474749660383LL) {
		for (lli x : v[2]) {
			if (!millerRabin(n, x)) return false;
		}
		return true;
	}
	for (lli x : v[3]) {
		if (!millerRabin(n, x)) return false;
	}
	return true;
}

void solve() {
	int n;
	cin >> n;
	
	lli sum = 0;
	vector<lli> v(n);
	for (auto &x : v) {
		cin >> x;
		sum += x;
	}
	
	lli nowLen = 0;
	for (int i = 0; i < n; ++i) {
		nowLen += v[i];
		if (2 * nowLen == sum) {
			cout << 0 << "\n";
			return;
		}
		if (2 * nowLen > sum) {
			lli gap1 = 2 * nowLen - sum;
			nowLen -= v[i];
			lli gap2 = sum - 2 * nowLen;
			cout << min(gap1, gap2) << "\n";
			return;
		}
	}
}

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

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

// typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) rep(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) rep(i,0,n)rep(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 1e6+10;

void solve(int _t){
	int n;
	cin >> n;
	int a[N], vis[N] = {0}, freq[N] = {0};
	rep(i, 0, n) cin >> a[i], freq[a[i]]++;
	sort(a, a+n);
	int ans = 0;
	for(int i = 0;  i < n; i++){
		if(vis[a[i]] == 0){
			if(freq[a[i]] == 1)
				ans++;
			vis[a[i]] = -1;
			for(int j = 2*a[i]; j < N; j+=a[i]) vis[j] = 1;
		}
	}
	cout << ans << endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}  

Measured memory_bytes: 12200
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<string, int> psi;

bool cmp(psi d1, psi d2){
    if(d1.first.size() != d2.first.size()){
        return d1.first.size() < d2.first.size();
    }
    return d1.first < d2.first;
}

signed main(){
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, 0, n){
        string s;
        int a;
        cin >> s >> a;
        mp[s] += a;
    }
    vector<psi> d;
    for(map<string, int>::iterator it = mp.begin(); it != mp.end(); it++){
        d. push_back(make_pair(it->first, it->second));
    }
    sort(all(d), cmp);
    rep(i, 0, d.size()){
        cout << d[i].first << ' ' << d[i].second << endl;
    }
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

int main(int argc, char** argv) {
  int n;
  cin >> n;
  int p[n];
  rep(i, n) {
    cin >> p[i];
  }

  int res = 0;
  for (int i = 1; i < n-1; ++i) {
    int left = p[i-1];
    int mid = p[i];
    int right = p[i+1];

    if (p[i-1] < p[i] && p[i] < p[i+1]) { //OK
      ++res;
    } else if (p[i+1] < p[i] && p[i] < p[i-1]) {
      ++res;
    } else {
      // Do nothing
    }
  }

  cout << res << endl;
}


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

struct aUnionFind {
	vector<pair<int, long long int>> data;
	aUnionFind(int size) : data(size, make_pair(-1, 0)) { }

	//y is w bigger than x
	bool unionSet(const int x, const int y, const long long int w) {
		const int rx(root(x).first), ry(root(y).first);
		if (rx != ry) {
			data[rx].first += data[ry].first; data[ry].first = rx;
			data[ry].second = w + data[x].second - data[y].second;
			return true;
		}
		else {
			return root(x).second + w == root(y).second;
		}
	}
	bool findSet(const int x, const int y) {
		return root(x) == root(y);
	}

	//x is belong to first
	//x is second bigger than first
	pair<int, long long int> root(const int x) {
		if (data[x].first < 0) {
			return make_pair(x, 0);
		}
		else {
			pair<int, long long int>ndata;
			ndata.first = root(data[x].first).first;
			ndata.second = data[x].second + root(data[x].first).second;
			return data[x] = ndata;
		}
	}
	int size(const int x) {
		return -data[root(x).first].first;
	}
};

int main() {
	int N, Q; cin >> N >> Q;
	vector<int>ids(N);
	iota(ids.begin(), ids.end(), 0);
	int num = N;
	aUnionFind uf(N+Q);
	while (Q--) {
		string st; cin >> st;
		if (st == "COMPARE") {
			int a, b; cin >> a >> b;
			a--; b--;
			int ap = ids[a];
			int bp = ids[b];
			const auto ar = uf.root(ap);
			const auto br = uf.root(bp);
			if (ar.first == br.first) {
				cout << br.second - ar.second << endl;
			}
			else {
				cout << "WARNING" << endl;
			}
		}
		else {
			int a, b, c; cin >> a >> b >> c;
			a--; b--;
			int ap = ids[a];
			int bp = ids[b];
			const auto ar = uf.root(ap);
			const auto br = uf.root(bp);
			if (ar.first == br.first) {
				const int sa = br.second - ar.second;
				assert(sa == c);
				uf.unionSet(bp, num,sa);
				ids[b] = num;
				ids[a] = bp;
			}
			else {
				const int sa = c;
				uf.unionSet(ap, bp, c);
				uf.unionSet(bp, num, sa);
				ids[b] = num;
				ids[a] = bp;
			}
			num++;
		}
	}
	return 0;
}

Measured memory_bytes: 6164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cfloat>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

double r;

int main() {
    cin >> r;

    printf("%.*lf\n", DBL_DIG, 2 * r * M_PI);

    return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i,a[100001];
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[n/2-1];
	return 0;
}



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

bool isPrime(int num) {
    if (num < 2) return false;
    if (num == 2) return true;
    if (num%2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i=3; i<=sqrtNum; i++) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    const int maxR = 1E+5 + 10;
    bool Prime[maxR], like2017[maxR];
    int accSum[maxR];
    rep(i, maxR) Prime[i] = isPrime(i);
    rep(i, maxR) {
        if ((i%2 == 1) && (Prime[i]) && (Prime[(i+1)/2])) like2017[i] = true;
        else like2017[i] = false;
    }
    accSum[0] = 0;
    for (int i= 1; i<maxR; i++) {
        accSum[i] = accSum[i-1] + like2017[i];
    }

    int Q, li, ri;
    cin >> Q;
    rep(i, Q) {
        cin >> li >> ri;
        cout << accSum[ri] - accSum[li-1] << endl;
    }

    return 0;
}

 

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " << endl

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  int n;
  cin >> n;

  vll a(n);

  for(int i=0;i<n;i++)
    cin >> a[i];
  
  ll ans = 0;

  for(int i=1;i<n;i++){
    if(a[i] >= a[i-1])
      continue;
    ans += (a[i-1]-a[i]);
    a[i] = a[i-1];
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 4780
#include<stdio.h>

int main() {
    int inp_1 = 0, 
        inp_2 = 0,
        mod = 0,
        store = 0;

    scanf("%d %d", &inp_1, &inp_2);
    if ( inp_1 < inp_2 ) {
        store = inp_1;
        inp_1 = inp_2;
        inp_2 = store;
    }

    else if ( inp_1 == inp_2 ) {
        printf("%d\n", inp_1);
        return 0;
    }

    mod = inp_1 % inp_2;
    while(mod != 0){
        inp_1 = inp_2;
        inp_2 = mod;
        mod = inp_1 % inp_2;
    }

    printf("%d\n", inp_2);
    return 0;
}



Measured memory_bytes: 2144
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	ss := [10][10]bool{}
	var k, s int
	for i := 0; i < m; i++ {
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			fmt.Scan(&s)
			s--
			ss[i][s] = true
		}
	}
	p := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&p[i])
	}

	ans := 0
	for bits := 0; bits < (1 << uint(n)); bits++ {
		ok := true
		for i := 0; i < m; i++ {
			cnt := 0
			for j := 0; j < n; j++ {
				if ss[i][j] && (bits>>uint(j))&1 == 1 {
					cnt++
				}
			}
			if cnt%2 != p[i] {
				ok = false
			}
		}
		if ok {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;


public class Main {

	
	public static void main(String[] args){
		
		
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder(1000);
		
		while(sc.hasNext()){
			
			
			
			String line = sc.next();
			
			if("0".equals(line)){
				break;
			}
			
			int sum = 0;
			
			for(int i=0; i< line.length();i++){
				
				int digit = Integer.parseInt(String.valueOf(line.charAt(i))); 
				sum += digit;
			}
			sb.append(sum + System.lineSeparator());
		}
		
		System.out.print(sb);
		
		sc.close();
		
	}

}



Measured memory_bytes: 26732
# coding: utf-8

a, b, M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = min(A) + min(B)
for i in range(M):
    x, y, c = map(int,input().split())
    price = A[x-1] + B[y-1] - c
    ans = min(ans,price)

print(ans)

Measured memory_bytes: 19556
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<lint,lint> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
char s[200005];
int tot1;
int n;
vector<int> g[200005];
int size[200005],dist[200005];
int start[200005],fin[200005],cnt;
int msum[200005];
void dfs(int v,int p){
  size[v]=1;
  start[v]=cnt;
  msum[cnt+1]=msum[cnt]+(s[v]=='1'?1:0);
  ++cnt;
  dist[v]=0;
  for(auto to:g[v]){
    if(to==p) continue;
    dfs(to,v);
    size[v]+=size[to];
    chmax(dist[v],dist[to]+1);
  }
  fin[v]=cnt;
}
lint add=0;
int subt1(int v){
  return msum[fin[v]]-msum[start[v]];
}
int g2[200005];
int ub[200005],lb[200005];
void dfs3(int v,int p,int down){//...lim)
  pair<int,int> most,sec;
  most=sec=mp(-1,-1);
  most.sc=down;
  most.fr=p;
  sec.sc=0;
  for(auto to:g[v]){
    if(to==p) continue;
    int val=dist[to]+1;
    if(most.sc<val){
      sec=most;
      most=mp(to,val);
    }else if(sec.sc<val){
      sec=mp(to,val);
    }
  }
  ub[v]=sec.sc;
  lb[v]=INF;
  if(s[v]=='1') lb[v]=0;
  if(most.sc>sec.sc){
    g2[v]=most.fr;
  }

  if(~p){
    if(down-1<dist[v]){
      if(tot1-subt1(v)>0) ++add;
    }else if(down-1>dist[v]){
      if(subt1(v)>0) ++add;
    }else{
      ++add;
    }
    dump(v);dump(add);
  }
  for(auto to:g[v]){
    if(to==p) continue;
    int d;
    if(to==most.fr){
      d=sec.sc+1;
    }else{
      d=most.sc+1;
    }
    dfs3(to,v,d);
  }
}

int main(){
  cin>>n;
  REP(i,n-1){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  scanf("%s",s);
  REP(i,n) if(s[i]=='1') ++tot1;

  dfs(0,-1);
  memset(g2,-1,sizeof(g2));
  dfs3(0,-1,0);

  priority_queue<pi,vector<pi>,greater<pi>>pq;
  REP(i,n){
    pq.push(mp(lb[i],i));
  }
  debug(g2,g2+n);
  while(!pq.empty()){
    pi cur=pq.top();pq.pop();
    if(cur.fr>n) continue;
    if(~g2[cur.sc] && lb[g2[cur.sc]]>ub[cur.sc]+1){
      lb[g2[cur.sc]]=ub[cur.sc]+1;
      pq.push(mp(lb[g2[cur.sc]],g2[cur.sc]));
    }
  }
  lint res=0;
  REP(i,n) res+=max(0,ub[i]-lb[i]+1);
  debug(lb,lb+n);
  debug(ub,ub+n);
  dump(add);
  res+=add;
    
  cout<<res<<endl;

  return 0;
}





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

int main(){
	int n;
	scanf("%d",&n);
	int arr[100002] = {0};
	int dn = 0;
	for (int i = 0; i < n; ++i)
	{
		int temp;
		scanf("%d",&temp);
		
		if (arr[temp] == 0)
		{
			dn++;
		}
		arr[temp]++;
	}
	// printf("%d\n", dn);
	int even = 0;
	int odd = 0;
	sort(arr,arr+100002);
	for (int i = 100001; i >= 100001 - dn + 1; --i)
	{
		// printf("%d  ", arr[i]);
		if (arr[i] == 0)
		{
			continue;
		}
		if (arr[i]%2 == 0)
		{
			even ++;
		}
		else{
			odd++;
		}
	}
	// printf("%d %d\n", even , odd);
	if (even % 2 == 0)
	{
		printf("%d\n", dn);
	}
	else
		printf("%d\n", dn-1);
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<bool> visited(n);
  int now = 0;
  while (k && !visited[now]) {
    visited[now] = true;
    now = a[now];
    --k;
  }
  if (!k) {
    cout << now+1 << endl;
    return 0;
  }
  int start = now, mod = 0;
  now = start;
  while (a[now] != start) {
    now = a[now];
    mod++;
  }
  mod++;
  k %= mod;
  int ans = start;
  while (k) {
    ans = a[ans];
    k--;
  }
  cout << ans+1 << endl;
  return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(long long a, long long b){
        return a>b;
    }
};

string s;
int n,cnt,bst=1e9;

int F(int x){
    int cnt=0,lt=0;
    string p,q;
    for(int i=0;i<n;i++){
        if(s[i]==x) lt++;
    }
    p=s;
    while(lt!=n-cnt){
        lt=0;
        q="";
        cnt++;
        for(int i=0;i<n-cnt;i++){
            if(p[i]==x || p[i+1]==x) q+=x,lt++;
            else q+=p[i];
        }
        p=q;
        //cout << x << ' ' << p << '\n';
    }
    return cnt;
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> s; n=s.lg;
    bool dif=1;
    for(int i='a';i<='z';i++){
        bst=min(bst,F(i));
    }
    cout << bst;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def std_in():
    return sys.stdin.readline().strip()


def main():
    s = std_in()
    if "RRR" in s:
        print(3)
    elif "RR" in s:
        print(2)
    elif "R" in s:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9096
#include <cstdio>
#include <algorithm>
static const int MAXN = 5e5 + 4;
static const int LOGN = 20;
static const int ALPHABET = 26;

int n, q;
char s[MAXN];
// f[position][token or ALPHABET - empty string] - first index where the shrunk string equals a given character
int f[MAXN][ALPHABET + 1];
// g[position][power of two] - going 2^i steps through f[*][ALPHABET], the stopping index, or MAXN if nonexistent
int g[MAXN][LOGN];

int main()
{
    for (n = 0; (s[n] = getchar()) != '\n'; ++n) s[n] -= 'a';

    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= ALPHABET; ++j) f[i][j] = g[i][j] = MAXN;
    for (int i = n - 1; i >= 0; --i) {
        f[i][s[i]] = i + 1;
        for (int token = s[i] + 1; token <= ALPHABET; ++token)
            f[i][token] = (f[i][token - 1] == MAXN ? MAXN : f[f[i][token - 1]][token - 1]);
        if (f[i][ALPHABET] != MAXN) for (int token = 0; token < s[i]; ++token)
            f[i][token] = f[f[i][ALPHABET]][token];
        g[i][0] = f[i][ALPHABET];
        for (int j = 1; j < LOGN; ++j)
            g[i][j] = (g[i][j - 1] == MAXN ? MAXN : g[g[i][j - 1]][j - 1]);
    }

    scanf("%d", &q);
    int l, r;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d", &l, &r); --l;
        for (int pot = LOGN - 1; pot >= 0; --pot)
            if (g[l][pot] <= r) l = g[l][pot];
        puts(l == r ? "Yes" : "No");
    }

    return 0;
}


Measured memory_bytes: 92928
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

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

	ll n, k;
	cin >> n >> k;

	if(k % 2 == 1) cout << (n/k)*(n/k)*(n/k) << endl;
	else{
		ll a = 0, i = k/2;
		while(i <= n){
			a++;
			i += k;
		}
		cout << a*a*a + (n/k)*(n/k)*(n/k) << endl;
	}
	rtn 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split(" ").map(&:to_i);

n_next_1 = (n-k).abs
n_next_2 = (n - (k * (n / k))).abs
n_next= [n_next_1, n_next_2].min
loop do
  break if n <= n_next
  n = n_next
  n_next = (n-k).abs
end

puts n


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

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }

int main() {
	string O, E;
	cin >> O >> E;

	int max = (O.length() > E.length()) ? O.length() : E.length();

	string result = "";
	repeat(i, max) {
		string o = "";
		if (i < O.length()) {
			o = O.substr(i, 1);
		}

		string e = "";
		if (i < E.length()) {
			e = E.substr(i, 1);
		}

		result += o + e;
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
void main() {
    int[] ab = readln.split.to!(int[]);
    ab ~= ab[0] + ab[1];
    writeln(ab.any!"a % 3 == 0" ? "Possible" : "Impossible");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
	char ch;
	int count[26] = {};

	while(cin >> ch){
		if (ch - 'a' >= 0 && ch - 'a' <= 26){
			count[ch - 'a']++;
		} else if (ch - 'A' >= 0 && ch - 'A' <= 26){
			count[ch - 'A']++;
		}
	}

	for(int i = 0; i < 26; i++){
		cout << (char)('a' + i) << " : " << count[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 0;
		int y = 0;
		int t = 0;
		boolean ans = true;
		for(int i = 0; i < n; i++) {
			int nt = sc.nextInt();
			int nx = sc.nextInt();
			int ny = sc.nextInt();
			int dt = Math.abs(nt - t);
			int dx = Math.abs(nx - x);
			int dy = Math.abs(ny - y);
			if(dx + dy > dt) {
				ans = false;
				break;
			} else if((dt - (dx + dy)) % 2 == 1) {
				ans = false;
				break;
			}
			t = nt;
			x = nx;
			y = ny;
		}
		if(ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


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

string s;
int cnt[26];
int ans;

signed main() {
	cin >> s;
	int n = s.size();
	ans = n * (n - 1) / 2;
	for (int i = 0; i < n; i++)cnt[s[i] - 'a']++;
	for (int i = 0; i < 26; i++) {
		ans -= cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans + 1 << endl;
}

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

#define int long long
#define INF 1000000007
const int n1=500;

 
int32_t main() 
{
int a[4];
a[1]=300000;
a[2]=200000;
a[3]=100000;
int x,y;
int result=0;
cin>>x>>y;
if((x<=3) && (y<=3))
{
    
if((x==1) && (y==1))
{
    result=a[x]+a[y]+400000;
}
else
{
    result=a[x]+a[y];
}

}
else if(x<=3)
{
    result=a[x];
}
else if(y<=3)
{
    result=a[y];
}
cout<<result<<endl;


return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, R, r[8], d[200][200], INF = 1e8;

int main() {
	cin >> n >> m >> R;
	inc(i, R) { cin >> r[i]; r[i]--; }
	
	inc(i, n) {
	inc(j, n) {
		d[i][j] = INF;
	}
	}
	inc(i, n) { d[i][i] = 0; }
	
	inc(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	
	inc(k, n) {
	inc(i, n) {
	inc(j, n) {
		setmin(d[i][j], d[i][k] + d[k][j]);
	}
	}
	}
	
	sort(r, r + R);
	int ans = INF;
	do {
		int sum = 0;
		inc(i, R - 1) { sum += d[r[i]][r[i + 1]]; }
		setmin(ans, sum);
	} while(next_permutation(r, r + R));
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
n,m = map(int, input().split())
a = [[] for _ in range(n)]
count = 1
for i in range(m):
    p,y = map(int, input().split())
    a[p-1].append([y, count])
    count += 1
b = []
for i,j in enumerate(a):
    j_sort = sorted(j)
    for k,l in enumerate(j_sort):
        b.append([l[1],str(i+1).zfill(6)+str(k+1).zfill(6)])
for i in sorted(b):
    print(i[1])

Measured memory_bytes: 49324
#include<stdio.h>

int main(){
  int A[100],i,j,n,minj,count=0,key;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);

  for(i = 0; i < n; i++){
    minj = i;

    for(j = i; j < n; j++){
      if(A[j] < A[minj])
	minj = j;
    }

    if(i != minj){
      key = A[minj];
      A[minj] = A[i];
      A[i] = key;
      count++;
    }
  }

  for(i = 0; i < n-1; i++)
    printf("%d ",A[i]);

  printf("%d\n",A[n-1]);
  
  printf("%d\n",count);
  
  return 0;
}

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

int main(int argc, char *argv[])
{
	int a[5];

	//???????????´??° W???H???x???y???r ????????????????????§??????????????????????????????
	scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);

	if (a[0] >= (a[2] + a[4]) && 0 <= (a[2] - a[4]))
		if (a[1] >= (a[3] + a[4]) && 0 <= (a[3] - a[4]))
			printf("Yes\n");
		else
			printf("No\n");
	else
		printf("No\n");

	return 0;
}

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

using ll=long long; 

void solve(){
	map<char, int> color;
	int n;
	cin>>n;
	char c;
	for(int i=0; i<n; i++){
		cin>>c;
		color[c]=1;
	}
	int cnt=color['P']+color['W']+color['G']+color['Y'];
	if(cnt==4)cout<<"Four";
	else{
		cout<<"Three"<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}


Measured memory_bytes: 256
N,M = map(int,input().split())
cnt = [0]*(N+10)
for i in range(M):
    a,b = map(int,input().split())
    cnt[a]+=1
    cnt[b]+=1

for c in cnt:
    if c%2 == 1:
        print('NO')
        import sys
        sys.exit()
print('YES')


Measured memory_bytes: 44632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
int n,cnt = 1;
struct node{
	int next;
	int to;
	node():next(-1){
	}
}e[N<<1];
int head[N];
int c[N];
void addEdge(int from,int to){
	e[cnt].to = to;
	e[cnt].next = head[from];
	head[from] = cnt++;
};
void dfs(int u,int pre,int s,int &ok){
	if(u == n){
		ok = s;
		return;
	}
	int tmp = head[u];
	while(tmp!=0){
		if(ok)break;
		if(e[tmp].to!=pre)
			dfs(e[tmp].to,u,s+1,ok);
		tmp = e[tmp].next;
	}
	if(ok){
		if(u!=1&&s<=ok/2)c[u] = 1;
		if(u!=n&&s>ok/2)c[u]=-1;
	}
	return;
}
void DFS(int u,int pre,int k,int &tot){
	if(c[u] == -k)return;
	tot++;
	int tmp = head[u];
	while(tmp!=0){
		if(e[tmp].to!=pre)DFS(e[tmp].to,u,k,tot);
		tmp = e[tmp].next;
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	int ok = 0;
	c[1] = 1;
	c[n] = -1;
	dfs(1,-1,0,ok);
	
	int s1 = 0,s2 = 0;
	DFS(1,-1,1,s1);
	DFS(n,-1,-1,s2);
	if (s1-s2>=1)
         printf("Fennec\n");
     else
         printf("Snuke\n");
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 10;
 
int n, m;
multiset<int> available;
vector<int> job[N];
 
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    job[a].push_back(b);
  }
 
  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : job[m - i])
      available.insert(x);
    if (!available.empty()) {
      ans += *prev(available.end());
      available.erase(prev(available.end()));
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b) {
        cout << 0 << endl;
    }
    else if(n == 1) {
        if(a != b) cout << 0 << endl;
        else cout << 1 << endl;
    } else if(n == 2) {
        cout << 1 << endl;
    }
    else cout << (b * (n - 1) + a - (a * (n - 1) + b)) + 1 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int a, b, c, d, e, f;

int amo=1, aja=0;

vector<int> x, y;

int main()
{
	read(a, b, c, d, e, f);
	for(int i=0; i*100*a <= f; ++i){
		for(int j=0; i*100*a + j*100*b <= f; ++j){
			x.pb(i*100*a + j*100*b);
		}
	}
	for(int i=0; i*c <= f; ++i){
		for(int j=0; i*c + j*d <= f; ++j){
			y.pb(i*c + j*d);
		}
	}
	for(int X:x){
		for(int Y:y) if(X+Y <= f && 100*Y <= e*X){
			int nm = X+Y, nj = Y;
			if(aja*nm <= amo*nj){
				amo = nm;
				aja = nj;
			}
		}
	}
	printf("%d %d\n", amo, aja);
	return 0;
}


Measured memory_bytes: 1400
//テンプレート
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(){
    int t,x;
    double ans;
    scanf("%d%d",&t,&x);
    ans = (double)t/(double)x;
    printf("%f\n",ans);
    return 0;
}


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

using namespace std;
int palindrome(string ch)
    {
    int n=ch.length();
    int test=1;
    for(int i=0;i<n/2;i++)
    {
        if (ch[i]!=ch[n-1-i])
        {
            test=0;
            break;
        }
    }
    return(test);
    }
int main()
{
    string ch;
    cin>>ch;
    int n=ch.length();
    if(palindrome(ch)==0)
        cout<<"No";
    else
    {
        string ch1=ch.substr(0,(n/2));
        string ch2=ch.substr((n/2)+1,n);
        if((palindrome(ch1)==1)and(palindrome(ch2))==1)
            cout<<"Yes";
        else
            cout<<"No";
    }


}


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

const int MXN = 2e5 + 5;

int diam = 0;
vector<int> adj[MXN];
int dp[MXN];

int dfs(int x, int p) {
  int mx1 = 0;
  int mx2 = 0;
  for (int y : adj[x]) {
    if (y == p) continue;
    int res = dfs(y, x);
    if (res > mx1) swap(res, mx1);
    if (res > mx2) swap(res, mx2);
  }
  diam = max(diam, mx1 + 1 + mx2);
  return mx1 + 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  dp[1] = 1;
  dp[3] = 1;
  dp[4] = 1;
  for (int i = 5; i < MXN; ++i) {
    dp[i] = (dp[i - 2] & dp[i - 3]) | (dp[i - 3] & dp[i - 4]);
  }
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  cout << (dp[diam]? "First" : "Second") << '\n';
}


Measured memory_bytes: 23936
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
#define int long long
#define ll long long 
#define F first
#define sqr(x) ((x) * (x))
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;
                        
typedef unsigned long long ull;
typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)2e6+ 222;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;


int a, b, c;

void solve () {
	int sum = 0;
	cin >> a >> b >> c;
	if (b + a >= c - 1) cout << b + c;
	else {
		cout << b + (b + a + 1);
	

	}	
}

signed main () {
    #ifdef Maga
        freopen("input", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);                                              
    int t = 1;
    while (t --) {
    	solve ();
    }
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
ll dp[20][180][2];
ll k,n;
ll getsum(ll a,vector<ll>&digitA)
{
    ll s=0;
    while(a)
    {
        digitA.pb(a%10);
        s+=a%10;
        a/=10;
    }
    return s;
}
ll Superb(ll indx,ll sum,ll cond,vector<ll>&digitA)
{
    if(indx==-1)
    {
        return sum;
    }
    if(dp[indx][sum][cond]!=-1&&cond!=1)return dp[indx][sum][cond];
    ll kk=(cond)?digitA[indx]:9;
    ll total=0;
    for(ll i=0; i<=kk; i++)
    {
        ll newcond=(i==digitA[indx])?cond:0;
        total=max(total,Superb(indx-1,sum+i,newcond,digitA));
    }
    if (!cond)
        dp[indx][sum][cond] = total;
    return total;
}
ll first(ll n)
{
    memset(dp,-1,sizeof dp);
    vector<ll>digitA;
    getsum(n,digitA);
    ll ans1=Superb(digitA.size()-1,0,1,digitA);
    cout<< ans1 <<endl;
}
int main()
{
    ll n;
    cin>>n;
    ll s=0,kk=n;
    first(n);
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n];
        long sum = 0;

        for (int i = 0; i < n + 1; i++) {
            a[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = scanner.nextInt();
        }

        for (int i = 0; i < n; i++) {
            if (a[i] <= b[i]) {
                sum += a[i];
                if (a[i+1] <= b[i] - a[i]) {
                    sum += a[i+1];
                    a[i+1] = 0;
                } else {
                    sum += b[i] - a[i];
                    a[i+1] -= b[i] - a[i];
                }
            } else {
                sum += b[i];
            }
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 63996
import java.util.ArrayList;
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());
		String s = sc.next();

		sc.close();


		ArrayList<Integer>[] list = new ArrayList[26];
		for (int i = 0; i < 26; i++) {
			list[i] = new ArrayList<Integer>();
		}

		for (int i = 0; i < N; i++) {
			list[s.charAt(i) - 'a'].add(i);
		}

		int Max = 0;

		for (int i = 0; i < N - Max; i++) {
//			System.out.println("i:" + i + list[s.charAt(i) - 'a']);
			for (int begin : list[s.charAt(i) - 'a']) {
//				System.out.println("i:" + i + ", begin:" + begin);
				if (begin <= i + Max) continue;
				while (true) {
					if(begin + Max + 1 > N) break;
//					System.out.println(s.substring(i, i + Max + 1) + ", " + s.substring(begin, begin + Max + 1));
					if (s.substring(i, i + Max + 1).equals(s.substring(begin, begin + Max + 1))) {
						Max++;
						if(begin - i <= Max) break;
					} else {
						break;
					}
				}
			}
			list[s.charAt(i) - 'a'].remove(0);
		}

		System.out.println(Max);

	}
}


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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var n = int.Parse(System.Console.ReadLine());

        Dictionary<string, int> dic = new Dictionary<string, int>();
        dic.Add("AC", 0);
        dic.Add("WA", 0);
        dic.Add("TLE", 0);
        dic.Add("RE", 0);
        for (int i = 0; i < n; i++)
        {
            dic[System.Console.ReadLine()]++;
        }

        Console.WriteLine("AC x " + dic["AC"]);
        Console.WriteLine("WA x " + dic["WA"]);
        Console.WriteLine("TLE x " + dic["TLE"]);
        Console.WriteLine("RE x " + dic["RE"]);

    }
}

Measured memory_bytes: 30976
N,M=map(int,input().split())
ans=[-1]*(N+1)
for i in range(M):
    s,c=map(int,input().split())
    if ans[s]==-1 :
        ans[s]=c
    elif ans[s]==c :
        pass
    else:
        print('-1')
        exit()

if N>=2 and ans[1]==0:
    print('-1')
    exit()
elif N>=2 and ans[1]==-1: #ここが間違ってた。
    ans[1]=1
else:
    pass

for j in range(len(ans)):
    if ans[j] == -1:
        ans[j] = 0

if N==1:
    FA=ans[-1]
elif N==2:
    FA=10*ans[-2]+ans[-1]
else:
    FA=100*ans[-3]+10*ans[-2]+ans[-1]
print(FA)

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

#include <vector>

#include <algorithm>

using namespace std;

#define repeat(n) for(int _ = 1; _ <= (n); _++)

int main()
{
	ios::sync_with_stdio(false);
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
#endif
	
	int n;
	cin >> n;
	
	static char s[100005];
	cin >> &s[1];
	
	int a[26] = {};
	for(int i = 1; i <= n; i++)
		a[s[i]-'a']++;
	
	int ans = 1;
	for(int i = 0; i < 26; i++)
		ans = (long long)ans * (a[i] + 1) % (int)(1e9 + 7);
	
	cout << ans - 1;
}


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

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

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

int main() {
    for (int i = 0; i < 7; ++i) {
        int a, b;
        cin >> a >> b;
        cout << a-b << "\n";
    }
    return 0;
}


Measured memory_bytes: 3108
n,m=map(int,input().split())
k=[]
a=[input().split()for _ in range(n)]
a.sort()
for i in range(n):
  k.append(a[i].pop(0))

ans=0
count=1

for j in range(int(k[0])):
  for h in range(n-1):
    if a[0][j] in a[h+1]:
      count+=1
  if count==n:
    ans+=1
  count=1

print(ans)

Measured memory_bytes: 3064
a = []
for _ in range(5):
    a.append(int(input()))
k = int(input())
flag = True
for i in range(4):
    for j in range(i+1,5):
        if a[j]-a[i]>k:
            flag=False
if flag:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,a[100];
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++){
		for(int j=0;j<n-1;j++)
			if(a[j]%i>a[j+1]%i)
				swap(a[j],a[j+1]);
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <cctype>

int main(void){
	using namespace std;
	
	string s[3];
	
	cin >> s[0] >> s[1] >> s[2];
	
	for(int i = 0; i < 3; ++i){
		char c = toupper(s[i][0]);
		cout << c;
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = [int(i) for i in input().split()]

#dp[i][done][extra]
if N % 2 == 0 :
  extra = 2
else :
  extra = 3
  
N += 1
A = A + [-float('inf')]
  
dp = [[[-float('inf')] * extra for _ in range(2)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N) :
  a = A[i]
  for j in range(2) :
    for k in range(extra) :
      # 取る場合
      if j == 0 :
        dp[i+1][1][k] = max(dp[i+1][1][k], dp[i][j][k] + a)
      # 取らない場合
      if j == 1 :
        dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k])
      if j == 0 and k != extra - 1 :
        dp[i+1][0][k + 1] = max(dp[i+1][0][k + 1], dp[i][j][k])

# for dp_ in dp :
  # print(dp_)

print(max(dp[-1][0][-1], dp[-1][1][-1]))

Measured memory_bytes: 190848
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b;
  a = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    b = 0;
    for (int j = 1; j < N - i; j++) {
      if (vec.at(b) < vec.at(j)) {
        b = j;
      }
    }
    if (i % 2 == 0) {
      a += vec.at(b);
    }
    else {
      a -= vec.at(b);
    }
    vec.at(b) = vec.at(N - 1 - i);
    vec.pop_back();
  }
  cout << a << endl;
}

Measured memory_bytes: 256
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

ll A, B, C, D, E, F;

void think() {
  A *= 100;
  B *= 100;

  long double ans = -1;
  ll ans_w = 0, ans_s = 0;

  for (int a = 0; a <= F / A + 10; ++a) {
    for (int b = 0; b <= (F - A * a) / B + 10; ++b) {
      ll w = A * a + B * b;
      // dump(a, b, w);

      if (w > F)
        continue;

      // dump(a, b);
      if (a + b == 0)
        continue;

      for (int c = 0; c <= (F - w) / C + 10; ++c) {
        for (int d = 0; d <= (F - w - C * c) / D + 10; ++d) {
          ll s = C * c + D * d;
          if (w + s > F)
            break;
          if (w / 100 * E < s)
            break;

          long double p = 100.d * s / (w + s);
          // dump(w, s, p);
          if (ans < p) {
            ans = p;
            ans_w = w;
            ans_s = s;
          }
        }
      }
    }
  }

  cout << (ans_w + ans_s) << " " << ans_s << endl;
}

int main() {
  ios::sync_with_stdio(false);

  cin >> A >> B >> C >> D >> E >> F;

  think();
}


Measured memory_bytes: 256