akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int num[1000];
  int n,y=0,count=0;
  cin>>n;
    for(int i=0;i<n;i++){
      cin>>num[i];
    }
  for(int j=0;j<100000;j++){
    for(int k=0;k<n;k++){
      if(num[k]%2==1){
        y++;
        break;
      }
      else{
        count++;
      num[k]/=2;
      }
    }
    if(y==1)
      break;
  }
  cout<<count/n<<endl;
}

Measured memory_bytes: 888
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int ss[500][27];
int c[27];
int cal(int x) {
	return (x - 1) * x / 2;
}
int n;
int l[27];
vi mx;
int tans = -1e9;
int val(vi t) {
	int ans = 0;
	memset(l, -1, sizeof(l));
	for (int i = 0; i < n; i++)
		ans += ss[i][t[i]], 
		ans -= c[t[i]] * cal(i - l[t[i]]), 
		l[t[i]] = i;
	for (int i = 0; i < 27; i++)
		ans -= cal(n - l[i]) * c[i];
	if (chkmax(tans, ans)) mx = t;
	return ans;
}
int test = 0;

std::mt19937 rd;
vi upd(vi s) {
	int nans = val(s);
	while (1.0 * clock() / CLOCKS_PER_SEC < 1.5) {
		int fl = 1;
		for (int i = 0; i < n; i++) 
			for (int j = 0; j < 26; j++) {
				vi e = s;
				e[i] = j;
				int na = val(e);
				if (chkmax(nans, na)) 
					s = e, fl = 0;
			}
		
		if (fl) {
			vector<pi> t(n);
			for (int i = 0; i < n; i++)
				t[i] = mp(ss[i][s[i]], i);
			sort(t.begin(), t.end());
			for (int u = 0; u < t.size(); u++) {
				for (int v = u + 1; v < t.size(); v++) {
					int i = t[u].se, j = t[v].se;
					if (s[i] == s[j]) continue;
				//	if (!fl) break;
					vi e = s;
					swap(e[i], e[j]);
					int na = val(e);
					if (chkmax(nans, na))
						s = e, fl = 0; 
				}
			}
		}
		if (fl) {
			for (int g = 0; g < 5; g++)
				s[rd() % n] = rd() % 26;
			nans = val(s);
			fl = 0;
		}
		if (test) cout << nans << endl;
	//	cout << fl << ' ' << 1.0 * clock() / CLOCKS_PER_SEC << endl;
		if (fl) break;
	}
	return s;
}
int main() {
	if (test) freopen("sample2.in", "r", stdin);
	cin >> n;
	for (int i = 0; i < 26; i++)
		cin >> c[i];
	vi cur(n);
	memset(l, -1, sizeof(l));
	for (int i = 0; i < n; i++) {
		int na = -1e9;
		for (int j = 0; j < 26; j++) {
			cin >> ss[i][j];
			int ea = ss[i][j];// + (cal(i - l[j] + 26) - cal(26)) * c[j]; 
			if (chkmax(na, ea))
				cur[i] = j;
		}
		l[cur[i]] = i;
	}	
	upd(cur);
	if (test) cout << tans << endl;
	else {
		for (auto v : mx) 
			cout << v + 1 << endl;
		cout << endl;
	}
//	cout << val(mx) << endl;
	return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

void init(int n, vector<int>& v){
  v.resize(n);
  for(int i = 0; i < n; i++){
    v[i] = i;
  }
}
int root(int a, vector<int>& v){
  if(v[a] == a) return a;
  return (v[a] = root(v[a], v));
}

bool same(int a, int b, vector<int>& v){
  return root(a,v) == root(b,v);
}

void unite(int a, int b, vector<int>& v){
  v[root(a,v)] = root(b,v);
}


int main(){
  int N;
  cin >> N;
  int K,L;
  cin >> K >> L;
  vector<int> road,train;
  init(N, road); init(N, train);
  for(int i = 0; i < K; i++){
    int p,q;
    cin >> p >> q;
    unite(p-1, q-1, road);
  }

  for(int i = 0; i < L; i++){
    int r,s;
    cin >> r >> s;
    unite(r-1, s-1, train);
  }

  map<pair<int, int>, int> mp;

  for(int i = 0; i < N; i++){
    pair<int, int> nRoot = { root(i, road), root(i, train) };
    auto itr = mp.find(nRoot);
    if(itr != mp.end()){
      mp[nRoot]++;
    }else{
      mp[nRoot] = 1;
    }
  }

  // vector<int> ans(N, 1);
  for(int i = 0; i < N; i++){
  //   for(int j = i+1; j < N; j++){
  //     if(same(i, j, road) && same(i, j, train)){
  //       ans[i]++;
  //       ans[j]++;
  //     }
  //   }
    // cout << ans[i];
    cout << mp[{root(i, road), root(i, train)}];
    if(i < N-1)
      cout << " ";
  }
  // for(int i = 0; i < N; i++){
  //   cout << ans[i];
  //   if(i < N-1)
  //     cout << " ";
  // }
  cout << endl;
  return 0;
}


Measured memory_bytes: 13568
import java.util.*;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String C1 = sc.next();
		String C2 = sc.next();
		
		if(C1.charAt(0) == C2.charAt(2) && C1.charAt(1) == C2.charAt(1) && C1.charAt(2) == C2.charAt(0)){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string ans;
  long long r=n%10;
  if(r==2 || r==4 || r==5 || r==7 || r==9)
    ans="hon";
  else if(r==0 || r==1 || r==6 ||r==8)
    ans="pon";
  else 
    ans ="bon";
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3628
N, K = map(int,input().split()) 

atk = 0

Hps = [int(x) for x in input().split()]

Hps.sort()

bsp = []
for sp in reversed(Hps):
    if K > 0:
        K -= 1
    else:
        bsp.append(sp)

for x in bsp:    
    atk += x

print(atk)


Measured memory_bytes: 26180
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, K);
  GVI(x, N);
  int zero_pos = lower_bound(ALL(x), 0) - x.begin();
  if (zero_pos == 0) {
    print(x[K - 1]);
  } else if (zero_pos == N) {
    print(-x[N - K]);
  } else {
    int ans = 1e9;
    for (int i = zero_pos - K; i <= zero_pos; ++i) {
      if (i < 0 || i + K > N)
        continue;
      ans = min(ans, abs(x[i]) + abs(x[i + K - 1]) +
                         min(abs(x[i]), abs(x[i + K - 1])));
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 640
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef std::pair<int,int> P;
#define mk std::make_pair
#define fr first
#define sc second
inline int in()
{
	int k=0;char ch=gt;bool p=1;
	while(ch<'-')ch=gt;if(ch=='-')ch=gt,p=0;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return p?k:-k;
}
const int N=2e5+5;
int f[N],fa[N];
struct node{int u,v,w;}E[N<<2];
inline bool operator<(const node &a,const node &b){return a.w<b.w;}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	int n=in(),Q=in(),tot=Q;
	memset(f,0x3f,n<<2);
	for(int i=1;i<=Q;++i)
	{
		int u=in(),v=in(),w=in();
		E[i]=(node){u,v,w};
		f[u]=std::min(f[u],w+1);
		f[v]=std::min(f[v],w+2);
	}
	for(int i=1;i<n;++i)f[i]=std::min(f[i],f[i-1]+2);
	f[0]=std::min(f[0],f[n-1]+2);
	for(int i=1;i<n;++i)f[i]=std::min(f[i],f[i-1]+2);
	for(int i=0;i<n-1;++i)E[++tot]=(node){i,i+1,f[i]};
	E[++tot]=(node){n-1,0,f[n-1]};
	std::sort(E+1,E+tot+1);
	ll mst=0;int cnt=1;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=tot&&cnt<n;++i)
	{
		int u=find(E[i].u),v=find(E[i].v);
		if(u==v)continue;++cnt;fa[u]=v;mst+=E[i].w;
	}
	printf("%lld\n",mst);
	return 0;
}


Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int h[100000] = {};
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    
    int dp[100001] = {};
    
    dp[1] = abs(h[1]-h[0]);
    
    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    
    cout << dp[N-1] << endl;
    
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll rev(ll a) {
  ll now = mod - 2, ans = 1;
  while(now) {
    if(now & 1) ans *= a, ans %= mod;
    a *= a, a %= mod, now >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, ans = 0, now;
  scanf("%lld%lld", &n, &k);
  k--;
  ll a[n], fact[n + 1];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  sort(a, a + n);
  fact[0] = 1;
  for(i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i, fact[i] %= mod;
  for(i = k; i < n; ++i) {
    now = fact[i] * rev(fact[k]), now %= mod;
    now *= rev(fact[i - k]), now %= mod;
    ans += a[i] * now, ans %= mod;
  }
  for(i = 0; i < n - k; ++i) {
    now = fact[n - i - 1] * rev(fact[k]), now %= mod;
    now *= rev(fact[n - i - k - 1]), now %= mod;
    ans -= a[i] * now, ans %= mod;
  }
  ans += mod;
  ans %= mod;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Collections;
import java.util.ArrayList;

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

    static class DigitsMultiplication {
        HashMap<Long, Long> map;
        long diff = Long.MAX_VALUE;
        long ansA;
        long ansB;

        static HashMap<Long, Long> primeFactorize(long x) {
            HashMap<Long, Long> result = new HashMap<>();
            for (long i = 2; i * i <= x; i++) {
                if (x % i != 0) {
                    continue;
                }
                long ex = 0;
                while (x % i == 0) {
                    ex++;
                    x /= i;
                }
                result.put(i, ex);
            }
            if (x != 1) {
                result.put(x, 1L);
            }
            return result;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();

            map = primeFactorize(n);
            List<Long> list = new ArrayList<>(map.keySet());
            list.sort(Collections.reverseOrder());

            List<Long> hoge = new ArrayList<>();
            for (long key : list) {
                int limit = map.get(key).intValue();
                for (int i = 0; i < limit; i++) {
                    hoge.add(key);
                }
            }

            dfs(hoge, 0, 1, 1);

            int result = Math.max(
                    String.valueOf(ansA).length(),
                    String.valueOf(ansB).length()
            );
            out.println(result);
        }

        public void dfs(List<Long> list, int index, long a, long b) {
            if (index == list.size()) {
                if (Math.abs(a - b) < diff) {
                    diff = Math.abs(a - b);
                    ansA = a;
                    ansB = b;
                }
            } else {
                dfs(list, index + 1, a * list.get(index), b);
                dfs(list, index + 1, a, b * list.get(index));
            }
        }

    }
}



Measured memory_bytes: 37368
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 19:11:44 2018

@author: maezawa
"""
infinity = 2*10**9

n = int(input())
adj = [[] for _ in range(n)]

for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(2,2+2*k,2):
        adj[u].append([ain[i],ain[i+1]])
    #print(*adj[u])

color = [0]*n
d = [infinity for _ in range(n)]
p = [0]*n
p[0] = -1
d[0] = 0

def dyk(s):
    cnt = 1
    cur = s
    candidates = set() # remaining nodes
    while True:
        for i, w in adj[cur]:
            if color[i] == 2:
                continue
            if d[i] > d[cur] + w:
                d[i] = d[cur] + w
                color[i] = 1
            candidates.add(i)
        min_d = infinity
        for j in candidates:
            if min_d > d[j]:
                min_node = j
                min_d = d[j]
        candidates.remove(min_node)
        p[min_node] = cur
        color[cur] = 2
        cur = min_node
        cnt += 1
        #print(cur, d)
        #print(candidates)
        if cnt == n:
            break
    return

dyk(0)
for i in range(n):
    print(i, d[i])

                    
                    


Measured memory_bytes: 6156
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1

nCa = 1
for i in range(n - a + 1, n + 1): #n*(n-1)*…*(n-a+1)
    nCa *= i
    nCa %= mod
for i in range(1, a + 1): #1/a
    nCa *= pow(i, mod - 2, mod)
    nCa %= mod

nCb = 1
for i in range(n - b + 1, n + 1): #n*(n-1)*…*(n-b+1)
    nCb *= i
    nCb %= mod
for i in range(1, b + 1): #1/b
    nCb *= pow(i, mod - 2, mod)
    nCb %= mod

ans -= (nCa + nCb)
ans %= mod
print(ans)

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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(1)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXN 1005

int n, m;
char plansza[MAXN][MAXN];
ll dp[MAXN][MAXN];
ll P=(1e9)+7;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i=1; i<=n; ++i)
	{
		cin >> plansza[i]+1;
		for (int j=1; j<=m; ++j)
		{
			if (i==1 && j==1)
			{
				dp[i][j]=1;
				continue;
			}
			if (plansza[i][j]=='#')
			{
				continue;
			}
			dp[i][j]=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=P;
		}
	}
	fprintf (out, "%lld\n", dp[n][m]);
	return 0;
}
/*
*/




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

int main() {
    long n, ans = LONG_MAX;
    cin >> n;
    for(long i = 1; i * i <= n; i++) {
        if(n % i == 0) ans = min(ans, n / i + i - 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>MARCH(5);
	rep(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'M') {
			MARCH[0]++;
		}
		else if (s[0] == 'A') {
			MARCH[1]++;
		}
		else if (s[0] == 'R') {
			MARCH[2]++;
		}
		else if (s[0] == 'C') {
			MARCH[3]++;
		}
		else if (s[0] == 'H') {
			MARCH[4]++;
		}
	}
	int i = 1;
	ll ans = 0;
	while (i < pow(2, 5)) {
		int count = 0;
		ll tmp = 1;
		rep(k, 5) {
			if (i&(1 << k)) {
				count++;
				tmp *=(ll) MARCH[k];
			}
		}
		if (count == 3) {
			ans += tmp;
		}
		i++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <algorithm>
#define rg register
#define llint long long
using namespace std;
const int N=1008611;

struct ios
{
	template <typename _tp>
	inline ios operator >> (_tp &x)
	{
		x = 0;int f = 1;char c = getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c<='9'&&c>='0';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x)
	{
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x) ++dgt,s[dgt] = x%10+'0',x/=10;
		while(dgt) putchar(s[dgt]),--dgt;
		return *this;
	}
	inline ios operator << (char x)
	{
		putchar(x);
		return *this;
	}
}io;

int n;
llint k,cnt;
int num[N],vis[N],nxt[N],apr[N],aia[N],ans[N],ljt[N];

int main()
{
	io >> n >> k;
	for(rg int i=1;i<=n;++i)
	{
		io >> num[i];
		if(vis[num[i]]==0) ++cnt,vis[num[i]] = i;
		if(apr[num[i]]!=0) nxt[apr[num[i]]] = i;
		apr[num[i]] = i;
	}
	for(rg int i=1;i<=n;++i)
		if(nxt[i]==0) nxt[i] = vis[num[i]];
	int nw = 0,kk = 1,fst = 1;
	while(1)
	{
		++nw;
		if(nw==1&&fst==0) break;
		if(nxt[nw]<=nw) 
			++kk;
		nw = nxt[nw],fst = 0;
	}
	nw = 0;k %= kk-1,cnt = 0;
	while(k>1)
	{
		++nw;
		if(nxt[nw]<=nw) --k;
		nw = nxt[nw];
	}
	if(k)
	{
		for(rg int i=nw+1;i<=n;++i)
		{
			if(aia[num[i]]==0) ++cnt,ans[cnt] = num[i],aia[num[i]] = cnt;
			else
			{
				while(ans[cnt]!=num[i])
					aia[ans[cnt]] = 0,--cnt;
				aia[num[i]] = 0,--cnt;
			}
		}
	}
	for(rg int i=1;i<=cnt;++i)
		io << ans[i] << ' ';
	io << '\n';
	return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);
    vector<int> v(n);
    for(int i=0;i<n;i++) scanf("%d",&v[i]);
    sort(v.begin(),v.end());
    double ans=v[0];
    for(int i=1;i<n;i++){
        ans=(ans+v[i])/2.0;
    }
    printf("%lf\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF =1e18;

int a[10];
int main () {
  
  for (int i=0; i<4; i++) {
    int n; cin >> n;
    a[n]++;
  }
  if (a[1] == 1 && a[4] == 1 && a[7] == 1 && a[9] == 1)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



int main(){
	vector<int>cnt(3, 0);
	string s;
	cin >> s;
	rep(i, 0, s.size()) {
		cnt[s[i]-'a']++;
	}

	sort(all(cnt));

	if (cnt[2]-cnt[0] <= 1) {
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}


	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<char>> data(h, vector<char>(w));

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> data.at(i).at(j);
        }
    }

    vector<int> y;
    vector<int> t;

    int count = 0;
    int ans = 0;

    for (int tmp = 0; tmp < (1 << h + w); tmp++)
    {
        y.clear();
        t.clear();
        count = 0;

        bitset<12> s(tmp);
        for (int i = 0; i < h; i++)
        {
            if (s.test(i) == 0)
            {
                y.push_back(i);
            }
        }
        for (int i = h; i < h + w; i++)
        {
            if (s.test(i) == 0)
            {
                t.push_back(i - h);
            }
        }

        bool check = false;

        for (const auto &e : y)
        {
            for (const auto &d : t)
            {
                if (data.at(e).at(d) == '#')
                {
                    count++;
                }
            }
        }

        if (count == k)
        {

            ans++;
        }
    }

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

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

int main(){
  int n,r;
  cin >> n >> r;
  int ans = r + 100*max(0,10-n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from functools import reduce

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, A, B = lr()
answer = pow(2, N, MOD) - 1  # ここから苦手なものを引く

# nCaのaが小さい場合
def cmb(n, r): # nCr
    num = reduce(lambda x, y: x * y % MOD, range(n, n - r, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, r + 1))
    return num * pow(den, MOD - 2, MOD) % MOD

answer -= cmb(N, A) + cmb(N, B)
print(answer % MOD)
# 50

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    
    ll ans = 0;
    for(ll i = 0; i < 3; i++){
        char c;
        cin >> c;
        ans += (c - '0');
    }
    cout << ans << endl;
    
    
    return 0;
}


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

int main(){
	int graph[100][100] = {};
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++) {
			int t;
			cin >> t;
			graph[now - 1][t - 1] = 1;
		}
	}
	for(int i = 0;i < n;i++){
		cout << graph[i][0];
		for(int j = 1;j < n;j++){
			cout << " " << graph[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
K, S = readline.split(' ').map(&:to_i)

count = 0
for x in (0..K)
  remain = S-x
  next if remain>2*K
  break if remain<0

  for y in (0..K)
    remain2 = S-x-y
    break if remain2<0
    next if remain2>K
    count += 1
  end
end
puts count

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

typedef long long ll;

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

    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    if(n<k){
        ans = min(n,k-n);
    }else{
        ans = min(n%k,k-n%k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vl vector <long>
#define vll vector < ll >
#define pll pair < ll , ll >
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MODCONST 1000000007
#define pinf 1e+18L+7
#define ninf 1e-18L+7

using namespace std;

void solve()
{
    ll n,k;
    cin>>n>>k;
    // 1*3+2*2+3*1 tot 4 k 2
    // 4+3+2+2+1+1+1 tot 4 k 1
    ll s = 0;
    n += 1;
    rep(i,k,n+1){
        // cout<<i<<" "<<n+1<<" "<<n+1-k<<endl;
        s += ((n+1-i)+(max((ll)0,i-1)*(n-i))%MODCONST)%MODCONST;
        s %= MODCONST;
    }
    cout<<s<<endl;
}

int main()
{
    fastio ;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll tc=1;
    //cin>>tc; //for number of testcases
    // ll ts = tc;
    while(tc--){
        // cout<<"Case #"<<ts-tc<<": "; // Google Codestub
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
import itertools
S = input().strip()
k = len(S)
tot = 0
for x in itertools.product((0,1),repeat=k-1):
    y = S[0]
    for i in range(k-1):
        if x[i]==0:
            y += S[i+1]
        else:
            y += "+"+S[i+1]
    tot += eval(y)
print(tot)

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

int main() {
  int N;
  while (cin >> N) {
    if (N == 0) { break; }
    vector<int> k(N);
    int result = 0;
    bool flag = false;
    for (int i = 0; i < N; ++i) {
      cin >> k[i];
    }
    for (int i = 0; i < N; ++i) {
      if (k[i] == 1) {
        result++;
      } else if (k[i] >= 2) {
        flag = true;
        result++;
      }
    }
    if (result == 0 || !flag) {
      cout << "NA" << endl;
    } else {
      cout << result + 1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1232
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, L, T = map(int, readline().split())
    position = []
    #0をL-1からーに時計回りに超える場合は+1
    #0からL-1に反時計回りに超える場合は-1
    count = 0
    for i in range(N):
        x,w = map(int, readline().split())
        if w==1:
            count += (x+T)//L
            position.append((x+T)%L)
        else:
            if x-T<0:
                count += (x-T+1)//L
            position.append((x-T)%L)
    position.sort()
    count %= N
    ans = position[count:] + position[:count]
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

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

int main() {
  int N,K;
  cin >> N >> K;
  set<int> snk;
  rep(i,K){
    int d;
    cin >> d;
    vector<int> A(d);
    rep(j,d){
      cin >> A[j];
      snk.insert(A[j]);
    }
  }
  int res = 0;
  rep(i,N){
    if(!snk.count(i+1)){
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3628
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int d,t,s = 0;
  cin >> d >> t;
  for (int i = 0; i < t; ++i)
  {
    int na;
    cin >> na;
    s += na;
  }
  if (s > d)
  {
    cout << -1;
  }
  else
  {
    cout << d-s;
  }
  return 0;
}


Measured memory_bytes: 3620
s=input()
d=999
import re
l=[[7],[6,8],[5,9]]+[[x] for x in range(4,0,-1)]
for n in l:
  for j in n:
    for i in re.findall('(?=('+str(j)+'..))',s):
      d=min(d,abs(753-int(i)))
  if d<800:break
print(d)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct Point {
	int x, y;
	Point operator*(int a) const { return Point{ x * a, y * a }; }
	Point operator+(const Point &that) const { return Point{ x + that.x, y + that.y }; }
};

int main() {
	int N;
	mt19937 re;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i) {
			scanf("%d", &a[i]);
			if(a[i] == 270)
				a[i] = -90;
		}
		if(accumulate(a.begin(), a.end(), 0) != 360) {
			puts("-1");
			continue;
		}
		function<vector<Point>(vector<int>)> rec = [&rec](vector<int> a) -> vector<Point> {
			vector<Point> P;
			int N = (int)a.size();
			if(N == 4) {
				assert(count(a.begin(), a.end(), 90) == 4);
				P.push_back({ 0, 0 });
				P.push_back({ 1, 0 });
				P.push_back({ 1, 1 });
				P.push_back({ 0, 1 });
				return P;
			}
			int mid = -1;
			rep(i, N) if(a[i] == 90 && a[(i + 1) % a.size()] == -90) {
				mid = i == 0 ? N - 1 : i - 1;
				break;
			}
			assert(mid != -1);
			rotate(a.begin(), a.begin() + mid, a.end());
			assert(a[1] == 90 && a[2] == -90);
			vector<int> b = a;
			b.erase(b.begin() + 1, b.begin() + 3);
			vector<Point> Q = rec(b);
			while(!(Q[0].y == Q[1].y && Q[0].x < Q[1].x)) {
				for(auto &p : Q)
					swap(p.x, p.y), p.x *= -1;
			}
			P.push_back(Q[0] * 2);
			P.push_back(Q[0] * 2 + Point{ 1, 0 });
			P.push_back(Q[0] * 2 + Point{ 1, 1 });
			P.push_back(Q[1] * 2 + Point{ 0, 1 });
			reu(i, 2, Q.size())
				P.push_back(Q[i] * 2);
			vector<int> xs, ys;
			for(auto p : P) {
				xs.push_back(p.x);
				ys.push_back(p.y);
			}
			sort(xs.begin(), xs.end());
			xs.erase(unique(xs.begin(), xs.end()), xs.end());
			sort(ys.begin(), ys.end());
			ys.erase(unique(ys.begin(), ys.end()), ys.end());
			for(auto &p : P) {
				p.x = (int)(lower_bound(xs.begin(), xs.end(), p.x) - xs.begin());
				p.y = (int)(lower_bound(ys.begin(), ys.end(), p.y) - ys.begin());
			}
			rotate(P.rbegin(), P.rbegin() + mid, P.rend());
			return P;
		};
		vector<Point> P = rec(a);
		for(auto p : P)
			printf("%d %d\n", p.x, p.y);
	}
	return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define N 1111116

int n,t,p[N],h[N],a[N];
vector<int> q,v[N],f;

void travel(int x){
	for (int i=0;i<(int)v[x].size();i++)
		if (!h[v[x][i]]) travel(v[x][i]);
	f.clear();
	for (int i=0;i<(int)v[x].size();i++)
		if (!h[v[x][i]]) f.push_back(a[v[x][i]]);
	f.push_back(-1);f.push_back(1e9);a[x]=-1;
	sort(f.begin(),f.end());
	for (int i=0;a[x]==f[i];)
		for (a[x]++;a[x]==f[i+1];) i++;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) p[i]=read();
	for (int i=1;i<=n;i++) v[p[i]].push_back(i);
	for (int i=t=1;i<=n;i++) t=p[t];
	for (;!h[t];t=p[t]) h[t]=1,q.push_back(t);
	for (int i=0;i<(int)q.size();i++) travel(q[i]);
	for (int i=1;i<(int)q.size();i++)
		if (a[q[i]]!=a[q[i-1]]) {printf("POSSIBLE\n");return 0;}
	printf(q.size()%2?"IMPOSSIBLE\n":"POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 43124
n, x = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)

result=0;
(n-1).times do|index|
  superior = [(a[index] + a[index+1]) - x, 0].max
  result +=superior
  if a[index+1] >= superior
    a[index+1] = a[index+1] - superior
  else
    rest = superior - a[index+1]
    a[index+1] = 0
    a[index] = a[index]-rest
  end
end

p result


Measured memory_bytes: 12292
s = list(str(input()))
a = 0
ans = []
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        a += 1
    else:
        ans.append(a)
        a = 0
if a != 0:
    ans.append(a)
print(max(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,j,n) for(int i=j;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int N,A[200005];

signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	map<int,int>mp;
	int ans=0;
	rep(i,N){
		ans+=mp[A[i]-i];
		mp[-A[i]-i]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 27796
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        
        if(n * a > b){
            System.out.println(b);
        }else{
            System.out.println(n * a);
        }
        
    }
}


Measured memory_bytes: 21716
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[]
a.sort()
for i in range(m):
	x,y=map(int,input().split())
	bc.append([x,y])
bc.sort(key=lambda x:-x[1])
k=0
for i in range(n):
	if a[i]>=bc[k][1]:
		break
	elif bc[k][0]!=0:
		bc[k][0]-=1
		a[i]=bc[k][1]
	else:
		k+=1
		if k>=m:
			break
		elif a[i]<bc[k][1]:
			bc[k][0]-=1
			a[i]=bc[k][1]
		else:
			break
print(sum(a))


Measured memory_bytes: 28728
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ld = long double;
constexpr ld PI = 3.14159265358979;
int main()
{
    int N;
    cin >> N;
    vector<ld> r(N);
    for (int i = 0; i < N; i++) {
        cin >> r[i];
    }
    sort(r.begin(), r.end(), greater<ld>{});
    ld maximum = 0;
    for (int i = 3; i <= N; i++) {
        vector<ld> v = r;
        do {
            vector<ld> prod(i);
            for (int j = 0; j < i; j++) {
                prod[j] = v[j] * v[(j + 1) % i];
            }
            sort(prod.begin(), prod.end());
            ld inf = -1;
            ld sup = 1;
            for (int j = 0; j < 30; j++) {
                const ld mid = (inf + sup) / 2;
                const ld lambda = mid * prod[0];
                ld sum = 0;
                for (int k = 0; k < i; k++) {
                    sum += acos(lambda / prod[k]);
                }
                if (sum < 2 * PI) {
                    sup = mid;
                } else {
                    inf = mid;
                }
            }
            inf *= prod[0];
            ld sum = 0;
            ld s = 0;
            for (int j = 0; j < i; j++) {
                const ld theta = acos(inf / prod[j]);
                s += theta;
                sum += prod[j] * sin(theta) / 2;
            }
            if (abs(s - 2 * PI) > 0.001) {
                continue;
            }
            maximum = max(maximum, sum);
        } while (prev_permutation(v.begin(), v.end()));
    }
    cout << fixed << setprecision(15) << maximum << endl;

    return 0;
}



Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<long long int> sum(n);
    sum[0] = a[0];
    for(int i = 1; i < n; i++){
        sum[i] = sum[i-1] + a[i];
    }

    int ans = 1;
    for(int i = n-2; i >= 0; i--){
        if(sum[i] >= (a[i+1]+1)/2){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
int par[10009];
int root(int x) {
    if(par[x]== x) return x;
    return par[x] = root(par[x]);
}
void unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return;
    par[x] = y;
}
bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
}
int n, q, tp, x, y;
int main() {
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; i++) par[i] = i;
    while(q--) {
        scanf("%d%d%d", &tp, &x, &y);
        if(tp == 0) unite(x, y);
        else {
            bool ret = same(x, y);
            puts(ret ? "1" : "0");
        }
    }
    return 0;
}

Measured memory_bytes: 3176
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();
  int n;
  cin >> n;
  vector<pii> vp;
  int check_sum = 0;
  repi(i, n)
  {
    string s;
    cin >> s;
    int a = 0, b = 0;
    for (auto c : s)
    {
      if (c == '(')
      {
        b++;
      }
      else if (c == ')')
      {
        if (b > 0)
          b--;
        else
          a++;
      }
    }
    vp.emplace_back(MP(a, b));
    check_sum += b - a;
  }
  if (check_sum != 0)
  {
    Yes(false);
    return 0;
  }

  vector<tuple<int, int, int>> v;
  repi(i, n)
  {
    auto [a, b] = vp[i];
    if (b - a > 0)
    {
      v.emplace_back(MT(-1, a, b));
    }
    else if (b - a == 0)
    {
      v.emplace_back(MT(0, a, b));
    }
    else
    {
      v.emplace_back(MT(1, -b, -a));
    }
  }
  sort(all(v));

  int t = 0;
  for (auto &&[type, a, b] : v)
  {
    if (type == 1)
    {
      swap(a, b);
      a = -a, b = -b;
    }
    int add = b - a;
    if (t - a < 0)
    {
      Yes(false);
      return 0;
    }
    t += add;
  }
  Yes(true);
  return 0;
}

Measured memory_bytes: 29492
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void){
    int H, N;
    cin >> H >> N;
    int A[N];
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];   
    }
    
    if(H > sum) cout << "No" << endl;
    else cout << "Yes" << endl;
     
}


Measured memory_bytes: 640
#include <stdio.h>
#define H 500000
void maxheap(int *,int,int);
void buildheap(int *,int);

int main()
{
  int A[H];
  int n,i,j,k;
  while(1)
    {
      scanf("%d",&n);
      if(n>=1 && n<=H)
	break;
    }
  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
    }
  buildheap(A,n);
  for(i=1;i<=n;i++)
    {
      printf(" %d",A[i]);
    }
  printf("\n");
  return 0;
}

void maxheap(int *A,int i,int heapsize)
{
  int l,r,largest,exchange;  
  l=2*i;
  r=2*i+1;
  if(l<=heapsize && A[l]>A[i])
    largest=l;
  else{
    largest=i;
  }
  if(r<=heapsize && A[r]>A[largest])
    largest=r;
  if(largest!=i)
    {
     
      exchange=A[i];
      A[i]=A[largest];
      A[largest]=exchange;
      maxheap(A,largest,heapsize);
    }
}
void buildheap(int *A,int h)
{
  int i;
  for(i=h/2;i>0;i--)
    maxheap(A,i,h);
}



Measured memory_bytes: 3652
// B - Choose Integers
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> a >> b >> c;
  vlli d;
  for (lli i = a; i <= 1000000; i += a)
  {
    d.pb(i);
  }
  // cout << d << endl;
  rep(i, 0, d.size())
  {
    if (d[i] % b == c)
    {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 11596
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int N,M;
  cin>>N>>M;
  if(N>=0 && M<=100 && N+M>=2)
  {
    cout<<(N*(N-1))/2 + (M*(M-1)/2);
  }
  else
  {
    cout<<"0";
  }
  return 0;
}


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

// i ~ N-1の範囲にNの約数が存在するか
bool has_divisor(int N, int i) {
  // ベースケース1
  if (i == N) {
    return false;
  }
  // ベースケース2
  if (N % i == 0) {
    // 実際にiはNの約数なので、i ~ N-1の範囲に約数が存在する
    return true;
  }

  // 再帰ステップ
  // i+1 ~ N-1の範囲の結果がi ~ N-1の範囲の結果となる
  // (ベースケース2によって、iがNの約数の場合は取り除かれているので、あとはi+1 ~ N-1の範囲を調べればよい)
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    // 1は素数ではない
    return false;
  }
  else if (N == 2) {
    // 2は素数
    return true;
  }
  else {
    // 2~(N-1)の範囲に約数が無ければ、Nは素数
    return !has_divisor(N, 2);
  }
}

int main() {
  int x;
  cin >> x;
  for(int i = x; i < INT_MAX; i++) {
    if(is_prime(i)) {
      cout << i << endl;
      break;
    }
  }
}



Measured memory_bytes: 256
A, B =map(int,input().split())
count = 1
'''
while A < B:
    count += 1
    A += (A-1)
    #count += 1
if A == B:
    count -= 1
#print(A)
print(count)
'''
p=A
if B==1:
    print(0)
else:
    while p<B:
        count+=1
        p+=(A-1)
    print(count)

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(1,n-1):
  if (a[i] > a[i-1] and a[i] < a[i+1]) or (a[i] < a[i-1] and a[i] > a[i+1]):
    count += 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>		/* strcmp関数を使うために使用 */
#include<ctype.h>		/* tolower関数を使うために使用 */

int main(void)
{
	int i,count=0;
	char number[10]={0};
	char bun[1000]={0};

	scanf("%s",number);
	for(i = 0;i < 10;i++)
	{
		/* tolower関数:大文字を小文字に変換する関数 */
		number[i] = tolower(number[i]);

	}
	while(1)
	{
		scanf("%s",bun);
		if(strcmp(bun,"END_OF_TEXT") == 0)
		{
			break;
		}
		for(i = 0;i < 1000;i++)
		{
			bun[i] = tolower(bun[i]);
		}
		if(strcmp(number,bun) == 0)
		{
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 552