akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    int ans=0;
    REP(i,n){
        REP(j,d){
            if(j%vec[i]==0){
                ans++;
            }
        }
    }
    cout<<ans+x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int P=1e9+7;
const int N=3e4+5;
inline int read(){
	register int x=0;
	register char ch=getchar();
	while(ch<'0'||ch>'9')	ch=getchar();
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x;
}
int n,m,k,a[N],vi[N];
ll fac[N],inv[N],f[N],g[N],tf[N],tg[N];
ll fsp(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
bool color(){
	for(int i=1;i<=m-k+1;i++){
		int flag=0;
		for(int j=1;j<=k;j++)	vi[j]=0;
		for(int j=0;j<k;j++)
			if(!vi[a[i+j]])	vi[a[i+j]]=1;
			else{
				flag=1;
				break;
			}
		if(!flag)	return true;
	}
	return false;
}
bool check(){
	for(int i=1;i<=k;i++)	vi[i]=0;
	for(int i=1;i<=m;i++)
		if(vi[a[i]])	return false;
		else	vi[a[i]]=1;
	return true;
}
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=read(),k=read(),m=read(),fac[0]=inv[0]=1;
	for(int i=1;i<=m;i++)	a[i]=read();
	for(int i=1;i<=n+k;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	ll ans=fsp(k,n-m)*(n-m+1)%P;
	if(color())	printf("%lld\n",ans);
	else	if(check()){
		tg[0]=1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<k;j++){
				f[j]=tf[j],g[j]=tg[j];
				if(j){
					f[j]=(f[j]+(tf[j-1]-tf[j]+P)*(k-j+1))%P;
					g[j]=(g[j]+(tg[j-1]-tg[j]+P)*(k-j+1))%P;
				}
			}
			for(int j=m;j<k;j++)	f[j]=(f[j]+g[j])%P;
			for(int j=k-1;~j;j--){
				f[j]=(f[j]+f[j+1])%P,tf[j]=0;
				g[j]=(g[j]+g[j+1])%P,tg[j]=0;
			}
			swap(f,tf),swap(g,tg);
		}
		ans=(ans-tf[0]*inv[k]%P*fac[k-m]%P+P)%P;
		printf("%lld\n",ans);
	}
	else{
		for(int i=1;i<=k;i++)	vi[i]=0;
		for(int i=1;i<=m;i++)
			if(!vi[a[i]])	vi[a[i]]=1;
			else{
				g[i-1]=1;
				break;
			}
		for(int i=k-1;~i;i--)	g[i]=(g[i]+g[i+1])%P;
		for(int i=1;i<=n;i++){
			for(int j=1;j<k;j++){
				f[j]=g[j];
				if(j)	f[j]=(f[j]+(g[j-1]-g[j]+P)*(k-j+1))%P;
			}
			for(int j=k-1;~j;j--)	f[j]=(f[j]+f[j+1])%P,g[j]=0;
			tf[i]=f[0],swap(f,g);
		}

		for(int i=0;i<=k;i++)	g[i]=vi[i]=0;
		for(int i=m;i;i--)
			if(!vi[a[i]])	vi[a[i]]=1;
			else{
				g[m-i]=1;
				break;
			}
		for(int i=k-1;~i;i--)	g[i]=(g[i]+g[i+1])%P,f[i]=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<k;j++){
				f[j]=g[j];
				if(j)	f[j]=(f[j]+(g[j-1]-g[j]+P)*(k-j+1))%P;
			}
			for(int j=k-1;~j;j--)	f[j]=(f[j]+f[j+1])%P,g[j]=0;
			tg[i]=f[0],swap(f,g);
		}

		tf[0]=tg[0]=1;
		for(int i=0;i+m<=n;i++)
			ans=(ans-tf[i]*tg[n-m-i]%P+P)%P;
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector <int> v(N);
  for( int i=0;i<N;i++ )
    cin >> v[i];
  sort(v.begin(), v.end());
  cout << abs(v.front()-v.back()) << endl;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

const int N = 100010;

int n,qu;
int fa[N],mark[N];

struct Node {int t,v;}q[N];

int gi() {
  int x=0,o=1; char ch=getchar();
  while(ch!='-' && (ch<'0'||ch>'9')) ch=getchar();
  if(ch=='-') ch=getchar(),o=-1;
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return o*x;
}

int find(int x, int ti) {
  return mark[x]<ti?x:fa[x]=find(fa[x],ti);
} 

int main() {
  while(scanf("%d%d", &n, &qu) && n+qu) {
    ll ans=0; int t=0;
    for(int i=2; i<=n; i++) fa[i]=gi(),mark[i]=qu+1;
    for(int i=1; i<=qu; i++) {
      char c; int x;
      scanf("%c", &c),x=gi();
      if(c=='M') mark[x]=min(mark[x],i);
      else q[t].t=i,q[t++].v=x;
    }
    while(t--) ans+=find(q[t].v,q[t].t);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4536
#include <iostream>

using namespace std;


int main(){
  long long int H,W,ans;
  cin>>H>>W;
  if(H==1||W==1){
    cout << 1<<endl;
    return 0;
  }
  
  if(H%2==0)
    ans=H/2*W;
  else
    ans=(H/2+1)*W-W/2;
    
  cout << ans<<endl;




  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, K ;
    cin >> A >> B >> C >> K ;
    int max = 0 ;

    while( K > 0 )
    {
        if( A )
        {
            max += 1 ;
            --A ;
        }
        else if( B )
        {
            --B ;
        }
        else if( C )
        {
            max -= 1 ;
            --C ;
        }
        --K ;
    }

    cout << max << endl ;


}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
    unsigned long long X;

    cin >> X;

    unsigned long long current = 100;
    unsigned long long count = 0;

    while (current < X) {
        current = (unsigned long long)(current * 1.01);
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3624
N = int(input())

plist = [(0,0,0)]
for _ in range(N):
	plist.append(tuple(map(int, input().split())))

judge = 'Yes'
for i in range(N):
	mae = plist[i]
	usi = plist[i+1]

	time_diff = usi[0] - mae[0]
	road = abs(usi[1] - mae[1]) + abs(usi[2] - mae[2])

	if time_diff < road:
		judge = 'No'
	elif time_diff >= road:
		yozyo = time_diff - road
		if yozyo % 2 != 0:
			judge = 'No'

print(judge)

Measured memory_bytes: 17320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_6B
{
    class Program
    {
        static void Main(string[] args)
        {
            var cardCount = int.Parse(Console.ReadLine());

            var cards = new int[4];

            for (var i = 0; i < cardCount; ++i)
            {
                var words = Console.ReadLine().Split(' ');

                var cardType = -1;
                switch (words[0])
                {
                    case "S": cardType = 0; break;
                    case "H": cardType = 1; break;
                    case "C": cardType = 2; break;
                    case "D": cardType = 3; break;
                }
                if (cardType < 0)
                {
                    continue;
                }

                cards[cardType] |= 1 << (int.Parse(words[1]) - 1);
            }

            for (var i = 0; i < cards.Length; ++i) 
            {
                var cardType = "";
                switch (i) {
                    case 0: cardType = "S"; break;
                    case 1: cardType = "H"; break;
                    case 2: cardType = "C"; break;
                    case 3: cardType = "D"; break;
                }

                var bitOfNumber = 1;
                for (var h = 0; h < 13; ++h)
                {
                    if ((cards[i] & bitOfNumber) == 0)
                    {
                        Console.WriteLine("{0} {1}", cardType, h + 1);
                    }
                    bitOfNumber <<= 1;
                }
            }


        }
    }
}

Measured memory_bytes: 5736
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define MEM(a,b) memset(a,b,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;

int main() {
	int n, k;
	cin >> n >> k;
	if (n == k) {
		cout << 1 << endl;
		return 0;
	}
	if ((n - 1) % (k - 1) == 0) {
		cout << (n - 1) / (k - 1)<< endl;
	}
	else cout << (n -1) / (k -1) + 1 << endl;
}



Measured memory_bytes: 256
S=input()

N=len(S)

lst=[0]*N
R_count=0
for i in range(N-1):
    if S[i]=='R' and S[i+1]=='R':
        R_count+=1
    if S[i]=='R' and S[i+1]=='L':
        R_count += 1
        lst[i]=R_count
        R_count=0
L_count=0
for i in range(N-1, 0, -1):
    if S[i]=='L' and S[i-1]=='L':
        L_count+=1
    if S[i]=='L' and S[i-1]=='R':
        L_count += 1
        lst[i]=L_count
        L_count=0
#print(lst)
i=0
while i < N:
    if lst[i] and lst[i+1]:
        mid=(lst[i]+lst[i+1])//2
        if (lst[i]-lst[i+1])%2==0:
            lst[i], lst[i+1] = mid, mid
        elif lst[i]>lst[i+1]:
            if lst[i]%2==1:
                lst[i], lst[i+1]= mid+1, mid
            else:
                lst[i], lst[i+1] =mid, mid+1
        elif lst[i]<lst[i+1]:
            if lst[i+1]%2==1:
                lst[i], lst[i + 1] = mid, mid + 1
            else:
                lst[i], lst[i + 1] = mid + 1, mid
        i+=1
    i+=1
print(' '.join(list(map(str, lst))))



Measured memory_bytes: 10612
#include <stdio.h>
#include <math.h>
#include <algorithm>

using std::max;

using ll = long long;
ll n;
ll nowt, nowa;

int main()
{
	scanf("%lld", &n);
	
	for (ll i = 0; i < n; ++i)
	{
		ll t, a;
		scanf("%lld %lld", &t, &a);
		ll tak = (ll)ceill((long double)nowt / t);
		ll aok = (ll)ceill((long double)nowa / a);
		ll mult = max(tak, aok);
		if (mult == 0)mult = 1;
		t *= mult; a *= mult;
		nowt = t;
		nowa = a;
	}
	printf("%lld", nowt + nowa);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

int n,m,r;
const int INF=1e7;
int land[200][200],sea[200][200],z[1000];
typedef pair<int,int> P;

int main(){


	while(scanf("%d %d",&n,&m),n){
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) land[i][j]=sea[i][j]=INF;
			land[i][i]=sea[i][i]=0;
		}
		
		for(int i=0;i<m;i++){
			int x,y,t;
			char c;
			scanf("%d %d %d %c",&x,&y,&t,&c);
			x--; y--;
			if(c=='S'){
				sea[x][y]=min(sea[x][y],t);
				sea[y][x]=min(sea[y][x],t);
			}else{
				land[x][y]=min(land[x][y],t);
				land[y][x]=min(land[y][x],t);			}
		}
		
		for(int k=0;k<n;k++){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					sea[i][j]=min(sea[i][j],sea[i][k]+sea[k][j]);
					land[i][j]=min(land[i][j],land[i][k]+land[k][j]);
				}
			}
		}
		
		scanf("%d",&r);
		for(int i=0;i<r;i++){
			scanf("%d",&z[i]);
			z[i]--;
		}
		
		vector<vector<int> > dp(1001,vector<int>(201,INF));
		dp[0][z[0]]=0;

		int res=INF;
		for(int i=1;i<r;i++){
			for(int j=0;j<n;j++){
				
				//z[i]???????????????????????¨??°???z[i-1]
				
				for(int k=0;k<n;k++){
					//????????????j?????§?§???????j??????k????????????k??????z[i]?????????				
					dp[i][k]=min(dp[i][k],dp[i-1][j]+land[z[i-1]][j]+sea[j][k]+land[k][z[i]]);
					if(i==r-1 && res>dp[i][k]) res=dp[i][k];
				}
				
				//????????§?§????
				dp[i][j]=min(dp[i][j],dp[i-1][j]+land[z[i-1]][z[i]]);
				if(i==r-1 && res>dp[i][j]) res=dp[i][j];
			}
		}

		printf("%d\n",res);
		
	}
}

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

using namespace std;

int main() {
    int k;
    int a,b;

    cin >> k;
    cin >> a >>b;

    int n=0;

    for(int i = 0; n < b; i++) {
        n=i*k;
        if(a <= n && n <= b){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int money[] = {10, 50, 100, 500};

vector<int> coin(int m) {
    vector<int> ret(4);
    repr(i,3,0) {
        if(m < money[i]) continue;
        ret[i] = m / money[i];
        m -= (m / money[i] * money[i]);
    }
    return ret;
}

signed main() {
    int n;
    bool first = true;
    while(cin >> n, n) {
        if(!first) cout << endl;
        else first = false;

        vector<int> ans(4);
        int c[5] = {};
        int cntcoin = 0;
        rep(i,0,4) {
            cin >> c[i];
            cntcoin += c[i];
        }

        int mi = INF;
        repq(i,0,c[0]) repq(j,0,c[1]) repq(k,0,c[2]) repq(l,0,c[3]) {
            int usecoin = i+j+k+l;
            int temp = i*money[0] + j*money[1] + k*money[2] + l*money[3];
            if(temp < n) continue;

            vector<int> backcoin = coin(temp - n);
            if(backcoin[0] && i) continue;
            if(backcoin[1] && j) continue;
            if(backcoin[2] && k) continue;
            if(backcoin[3] && l) continue;
            int cntbackcoin = 0;
            rep(i,0,4) cntbackcoin += backcoin[i];
            if(mi > (cntcoin - usecoin + cntbackcoin)) {
                mi = cntcoin - usecoin + cntbackcoin;
                ans = vector<int>{i, j, k, l};
            }
        }

        rep(i,0,4) {
            if(ans[i]) printf("%lld %lld\n", money[i], ans[i]);
        }
    }
    return 0;
}

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

using namespace std;

long N;
string reply;

int const MALE = 0;
int const FEMALE = 1;
int const VACANT = 2;
int ask_counter = 0;

int reply_to_number(string reply) {
    if (reply == "Vacant") return VACANT;
    if (reply == "Male") return MALE;
    return FEMALE;
}

int ask(int q) {
    cout << q << endl;
    cin >> reply;
    int reply_num_half = reply_to_number(reply);
    if (reply_num_half == VACANT) exit(0);
    return reply_num_half;
}


int main() {
#ifdef __APPLE__
    freopen("input0.txt", "r", stdin);
#endif

    cin >> N;
    long l = 0;
    long r = N-1;

    int ls = ask(0);
    int rs = ask(r);
    long m = (l + r) / 2;
    int ms = ask(m);

    while (true) {
        if (((m - l) % 2 == 0 && ms == ls) || ((m - l) % 2 == 1 && ms != ls)) {
            l = m;
            ls = ms;
        } else {
            r = m;
            rs = ms;
        }
        m = (l + r) / 2;
        ms = ask(m);
    }

    return 0;
}

Measured memory_bytes: 852
#include<stdio.h>

int main()

{

    long long int a,b,i,X=1,Y=1,Lim=1000000000000000000;

    scanf("%lld",&a);

    long long int A[a+5];

    for(i=0;i<a;i++){

        scanf("%lld",&A[i]);

    }

        for(i=0;i<a;i++){


        if(A[i]==0){

                X=0;
                break;

        }

        else if(Lim/Y>=A[i]) Y=Y*A[i];

        else X=2;


    }

        if(X==0) printf("0\n");
        else if(X==1) printf("%lld\n",Y);
        else if(X==2) printf("-1\n");

    return 0;
}


Measured memory_bytes: 2412
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int as[3];
int main(){

  cin>>N;
  for(int i=0;i<N;i++)cin>>as[i];
  int maxV=0;
  for(int i=0;i<N;i++)maxV=max(maxV,as[i]);
  vector<int> v;
  for(int j=1;j<=maxV;j++){
    bool ok=true;
    for(int i=0;i<N;i++){
      if(as[i]%j!=0){
        ok=false;
        break;
      }
    }
    if(ok)v.push_back(j);
  }
  for(int i=0;i<(int)v.size();i++)
    cout<<v[i]<<endl;
  
  
  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  map<ll, int> mp;

  ll t = (ll)sqrt(n);
  for (ll i = 1; i <= t; i++) {
    for (ll j = 1; j <= t; j++) {
      for (ll k = 1; k <= t; k++) {
        ll calc1 = i + j + k;
        calc1 *= calc1;
        ll calc2 = i * j + j * k + k * i;
        calc1 -= calc2;
        mp[calc1]++;
      }
    }
  }

  for (ll i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 5888
N = int(input())
s = [int(input()) for i in range(N)]
S = sum(s)
a = sorted(s)
i = 0
flag = 0

if S % 10 != 0:
	print(S)
else:
	while i < N:
		if a[i] % 10 != 0:
			print(S - a[i])
			flag = 0
			break
		else:
			i += 1
			flag = 1

if flag == 1:
	print(0)


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int N,M;
  cin >> N >> M;
  vll a(N);
  repeat(i,N){
    cin >> a[i];
  }
  if(2*(N-1-M)>N){
    cout << "Impossible" << endl;
    return 0;
  }
  vector<priority_queue<ll>> Q(N);
  UnionFind uf(N);
  repeat(i,M){
    int x,y;
    cin >> x >> y;
    uf.unionSet(x,y);
  }
  repeat(i,N){
    Q[uf.root(i)].push(-a[i]);
  }
  vector<Pii> v;
  repeat(i,N){
    v.push_back({-uf.size(i),uf.root(i)});
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  ll ans = 0;
  for(int i=1;i<v.size();i++){
    ans -= Q[v[0].second].top()+Q[v[i].second].top();
    Q[v[0].second].pop();
    Q[v[i].second].pop();
    while(!Q[v[i].second].empty()){
      Q[v[0].second].push(Q[v[i].second].top());
      Q[v[i].second].pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    ll n;
    string s;
    std::cin >> n;
    std::cin >> s;
    
    for (int i = 0; i < s.length(); i++) {
        std::cout << (char)('A'+(s[i]-'A'+n)%26);
    }
    std::cout << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define INF 0x3f3f3f3f
using namespace std;
typedef unsigned long long LL;
const int maxn=1e5+7;
const int mod=1e9+7;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}   
int main(){
	int l;
	cin>>l;
	printf("%.10lf\n",(double)l*l*l/27.0);
	return 0;
}

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

int main(){
    int N;
    int Y;
    int hoge = -1, fuga = -1, piyo = -1;
    cin >> N >> Y;
    for (int a = 0; a <= N; ++a){
        for (int b = 0; b + a <= N; ++b){
            int c = N -a -b;
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {
                hoge = a;
                fuga = b;
                piyo = c;
            }
        }
    }
    cout << hoge  << " " << fuga << " " << piyo << endl;
}

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

int main() {

	int n;
	cin >> n;

	ll ans = 0ll;
	for(int i = 1; i <= n; i++) {
		if(i % 3 == 0 || i % 5 == 0) continue;
		else ans += (ll)i;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    
    int T;
    cin >> T;
    
    int amari;
    //千の位
    int Thousands;
    Thousands = T / 1000;
    amari = T % 1000;
    
    //百の位
    int Hundreds;
    Hundreds = amari / 100;
    amari =  amari  % 100;
   
 //十の位
    int Ten;
    Ten = amari /10;
    amari = amari % 10;
   
    //一の位
    int One;
    One = amari;
    
    
    
    bool isYes = false;
    
    if(Thousands == Hundreds && Hundreds == Ten){
        isYes = true;
    }else if(Hundreds == Ten && Ten == One){
        isYes = true;
    }
    
    //配列の中身を見るため
    // for(int i=0; i<5; ++i){
    //     cout << (int)T[i] << endl;
    //}
    
    if(isYes){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 085 A - Already 2018
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/3
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

char s[10];

void solve() {

    s[3] = '8';
    printf("%s\n", s);

}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val B = listOfInt()
    val C = listOfInt()
    var ans = 0
    var next = -1 
    for (n in 0 until N) {
      val i = A[n] - 1
      if (i == next) ans += C[i - 1]
      ans += B[i]      
      next = i + 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }

Measured memory_bytes: 37872
#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 D, T, S;
	cin >> D >> T >> S;
	if(D <= T * S)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3588
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  n,m,l,*t=map(int,open(0).read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  print('\n'.join(map(str,map(int,[d[i]for i in zip(*[iter(t[m*3+1:])]*2)]))))
main()

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define show(x) cout<<(x)<<endl
#define REP(i,a,n) for (int i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef string str;
/*FIN*/
int x;
bool cmp(int a, int e) {
	if(abs(x-a) != abs(x-e))
		return abs(x-a) < abs(x-e);
	return a<e;
}

int main() {
	FAST;
	int n,id;
	int d[101];
	cin>>x>>n;
	REP(i,0,n) cin>>d[i];
	sort(d,d+n);
	V<int> b;
	REP(i,0,102) {
		if(!binary_search(d,d+n,i))
			b.PB(i);
	}
	sort(ALL(b),cmp);
	show(b[0]);
	return 0;
}


Measured memory_bytes: 3656
import math

N, M = map(int, input().split())
if abs(N-M) == 1:
  ans = math.factorial(N)*math.factorial(M)
elif abs(N-M) == 0:
  ans = math.factorial(N)*math.factorial(M)*2
else:
  ans = 0
print(ans%(10**9+7))

Measured memory_bytes: 5196
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

N = input()

ans = 0

for s in N:
    ans += int(s)

if ans % 9 == 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9188
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N;
	string s, t;
	cin >> s >> t;
	for (int i = N; i >= 0; i--) {
		bool flag = true;
		for (int j = 0; j < i; j++) {
			flag &= t[j] == s[N - i + j];
		}
		if (flag) {
			cout << N * 2 - i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
K = int(input())

s = set()
x = 7 % K
i = 1
while x not in s:
	if x == 0:
		print(i)
		break
	else:
		s.add(x)
		x = (x * 10 + 7) % K
		i += 1
else:
	print(-1)

Measured memory_bytes: 77948
unittest
{
	assert( [ "3" ].parse.expand.solve == 4 );
	assert( [ "6" ].parse.expand.solve == 30 );
	assert( [ "1000" ].parse.expand.solve == 972926972 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

const MOD = 10 ^^ 9 + 7;

auto solve( long n )
{
	long[ long ] ms;
	
	// 階乗の各項を素因数分解する
	for( auto i = 2L; i <= n; i++ )
	{
		auto r = i;
		foreach( p; n.primes )
		{
			if( r < 2 ) break;
			
			auto m = 1L;
			while( r % p == 0 )
			{
				r /= p;
				if( p !in ms ) ms[ p ] = 1;
				else           ms[ p ]++;
			}
		}
	}
	
	// 素因数分解した結果の各乗数+1を掛け算すると約数の個数が出る
	auto ans = 1L;
	foreach( m; ms )
	{
		ans = ans * ( m + 1 ) % MOD;
	}
	return ans;
}

auto primes( long n )
{
	static memo = [ 2L ];
	static n_max = 2L;
	
	if( n <= n_max ) return memo.retro.find!( ( a ) => a <= n ).retro;
	
	for( auto i = n_max + 1; i <= n; i++ )
	{
		if( !memo.canFind!( ( a ) => i % a == 0 ) ) memo ~= i;
	}
	n_max = n;
	
	return memo;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N = 2e5+5;
const int mod = 1e9+7;
int n,a[N],cnt[N],S=1,z[N],st[N],ed[N],D[N],ID[N],c1[N],c2[N];
int fastpow(int a,int b){
	int res=1;
	while (b) {if (b&1) res=1ll*res*a%mod;a=1ll*a*a%mod;b>>=1;}
	return res;
}
void mdf(int k,int v){while(k<=n)c1[k]=(c1[k]+v)%mod,++c2[k],k+=k&-k;}
int qry1(int k){int s=0;while(k)s=(s+c1[k])%mod,k^=k&-k;return s;}
int qry2(int k){int s=0;while(k)s+=c2[k],k^=k&-k;return s;}
int main(){
	n=gi();
	for (int i=1;i<=n;++i) ++cnt[a[i]=gi()];
	for (int i=n;i>=1;--i) cnt[i]+=cnt[i+1];
	for (int i=1;i<=n;++i){
		cnt[i]-=n-i;
		if (cnt[i]<=0) return puts("0"),0;
		S=1ll*S*cnt[i]%mod;
	}
	st[0]=D[0]=1;
	for (int i=1;i<=n;++i){
		int x=1ll*(cnt[i]-1)*fastpow(cnt[i],mod-2)%mod;
		if (!x) ed[z[i-1]]=i-1,st[z[i]=z[i-1]+1]=i,D[i]=D[i-1];
		else z[i]=z[i-1],D[i]=1ll*D[i-1]*x%mod;
		ID[i]=fastpow(D[i],mod-2);
	}
	ed[z[n]]=n;int inv2=(mod+1)>>1,ans=0;
	for (int i=1;i<=n;++i){
		ans=(ans+1ll*(qry1(a[i])-qry1(st[z[a[i]]]-1)+mod)*D[a[i]]%mod*S%mod*inv2)%mod;
		mdf(a[i],ID[a[i]]);
	}
	memset(c1,0,sizeof(c1)),memset(c2,0,sizeof(c2));
	for (int i=n;i;--i){
		ans=(ans-1ll*(qry1(a[i]-1)-qry1(st[z[a[i]]]-1)+mod)*D[a[i]]%mod*S%mod*inv2%mod+mod)%mod;
		ans=(ans+1ll*qry2(a[i]-1)*S)%mod;
		mdf(a[i],ID[a[i]]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7168
#include "bits/stdc++.h"

using namespace std;

int main() {
   int n;
   cin >> n;
   int l[n];
   int sum=0;
   int mx=0;
   for(int i=0;i<n;i++){
       cin >> l[i];
       sum+=l[i];
       mx=max(mx,l[i]);
   }
   if(mx<(sum-mx)){
       puts("Yes");
   }
   else{
       puts("No");
   }
   return 0;
}

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

int main(void)
{
    ll n, k, c;
    cin >> n >> k >> c;

    string s;
    cin >> s;

    auto getPositions = [&]() {
        vector<int> res;
        for (int i = 0; i < n && res.size() < k;)
        {
            if (s[i] == 'o')
            {
                res.push_back(i);
                i += c + 1;
            }
            else
            {
                ++i;
            }
        }
        return res;
    };
    vector<int> l, r;
    l = getPositions();
    reverse(s.begin(), s.end());
    r = getPositions();
    rep(i, k) r[i] = n - 1 - r[i];
    reverse(s.begin(), s.end());

    vector<int> lastL(n + 1, -1);
    rep(i, k) lastL[l[i] + 1] = i;
    rep(i, n)
    {
        if (lastL[i + 1] == -1)
            lastL[i + 1] = lastL[i];
    }
    vector<int> lastR(n + 1, -1);
    rep(i, k) lastR[r[i]] = i;
    for (int i = n - 1; i >= 0; --i)
    {
        if (lastR[i] == -1)
            lastR[i] = lastR[i + 1];
    }
    rep(i, n)
    {
        if (s[i] == 'x')
            continue;
        int li = lastL[i];
        int ri = lastR[i + 1];
        int cnt = 0;
        if (li != -1)
            cnt += li + 1;
        if (ri != -1)
            cnt += ri + 1;
        if (li != -1 && ri != -1 && r[ri] - l[li] <= c)
        {
            cnt--;
        }
        if (cnt >= k)
            continue;
        cout << i + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4984
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()
    l = len(S)
    x = S.count("o")
    y = 15 - l

    if x + y >= 8:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
      if (a[i] >= a[i - 1] && a[i] <= a[i + 1])
        ans++;
      else if (a[i] <= a[i - 1] && a[i] >= a[i + 1])
        ans++;
    }
    cout << ans;
    return 0;
}


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

// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 100007

#define ll long long int

ll mod=998244353;
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());
	int k=n-1;
	long long int ans=a[k];
	k--;
	for(int i=0;i<n-2;i++){
		ans+=a[k];
		k-=i%2;
	}
	cout<<ans<<endl;

}

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

int main()
{
  int N,l,r=0,s;
  cin >> N ;
  for(int i = 0; i<N; i++ )
  {
    cin >> l >> r;
    s+=r-l+1;
  }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==1) n=14;
    if(m==1) m=14;
    if(n>m) cout<<"Alice"<<endl;
    else if(n<m) cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

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

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

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

main () {
    to_pray();
    
    int n;
    cin >> n;

    cout << pow(n, 3);
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    cerr << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=n-1;i>0;i--){
		if(a[i]<a[i-1]){
		a[i-1]--;
		}
		if(a[i]<a[i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
  cout<<"Yes"<<endl;
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
#define ANS(s) cout << s << endl


using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}



int main(void) {
    string C[2];
    cin >> C[0] >> C[1];
    if (C[0][0] == C[1][2] && C[0][1] == C[1][1] && C[0][2] == C[1][0]){
        cout << "YES\n";
    }else{
        cout << "NO\n";
        
    }
    return 0;
    
}


Measured memory_bytes: 256
# abc166 C
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

ab = m.times.map {
  gets.split.map(&:to_i)
}

ten = Array.new(n+1) { {rin: []} }

####

ab.each do |(a,b)|
  ten[a][:rin] << b
  ten[b][:rin] << a
end

cnt = 0

ten[1..-1].each_with_index do |t, ind|
  hh = h[ind]
  cnt += 1 if t[:rin].all? { |tr|
    h[tr-1] < hh
  }
end

p cnt




Measured memory_bytes: 48140
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if ((i % 3 != 0) && (i % 5 != 0)) sum += i; 
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35780
#include <iostream>

using namespace std;


int main() {
    string s;
    cin >> s;

    bool tried_dreamer = false;
    while (!s.empty()) {
        if (s.find("dream") == 0) {
            if (s.find("dreamer") == 0) {
                if (tried_dreamer) {
                    tried_dreamer = false;
                    s.erase(s.begin(), s.begin() + 5);
                } else {
                    if (s.length() == 7 || s.substr(7, 5) == "erase" || s.substr(7, 5) == "dream") {
                        s.erase(s.begin(), s.begin() + 7);
                    } else {
                        tried_dreamer = true;
                    }
                }
            } else {
                s.erase(s.begin(), s.begin() + 5);
            }
        } else if (s.find("eraser") == 0) {
            s.erase(s.begin(), s.begin() + 6);
        } else if (s.find("erase") == 0) {
            s.erase(s.begin(), s.begin() + 5);
        } else {
            break;
        }
    }

    cout << (s.empty() ? "YES" : "NO") << endl;


    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
int n,q;
int i,j,count=0;
int left,right,mid;

scanf("%d",&n);
int S[n];
for(i=0;i<n;i++){
  scanf("%d",&S[i]);
}
scanf("%d",&q);
int T[q];
for(i=0;i<q;i++){
  scanf("%d",&T[i]);
}
for(i=0;i<q;i++){
  left = 0;
  right = n;
  while(left<right){
    mid=(left+right)/2;
    if(T[i]==S[mid]){
      count++;
      break;
    }
    else if(T[i]>S[mid]){
      left = mid+1;
    }
    else if(T[i]<S[mid]){
      right=mid;
    }
  }
}
printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2384
// AOJ 0508: String With Rings
// 2017.12.3 bal4u@uu

#include <stdio.h>
#include <string.h>

int to[101][101], sz[101];
char mk[101];
int ans;

void dfs(int x, int len)
{
	int i;

	if (len > ans) ans = len;
    mk[x] = 1;
	for (i = 0; i < sz[x]; i++) {
		if (!mk[to[x][i]]) {
			dfs(to[x][i], len + 1);
			mk[to[x][i]] = 0;
        }
    }
}
 
int main()
{
    int n, m, i, a, b;

    while (scanf("%d", &n) && n > 0) {
		memset(sz, 0, sizeof(sz));
	    for (m = 0, i = 0; i < n; i++) {
			scanf("%d%d", &a, &b);
			if (a > m) m = a;
			if (b > m) m = b;
			a--, b--;
			to[a][sz[a]++] = b, to[b][sz[b]++] = a;
	    }

		ans = 0;
		for (i = 0; i < m; i++) {
			memset(mk, 0, m);
			dfs(i, 1);
		}
		printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1756
n = int(input())
s = input()
count = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      check_1 = False
      check_2 = False
      check_3 = False
      for i in range(n):
          if s[i] == str(a):
            check_1 = True
            nex = i
            break
      if check_1 == True:
          for j in range(nex + 1,n):
            if s[j] == str(b):
              check_2 = True
              ne = j
              break
      if check_2 == True:
          for t in range(ne+1,n):
            if s[t] == str(c):
              count += 1
              break
print(count)
  

Measured memory_bytes: 45532
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int A = 1e5 + 2;
const int mod = 1e9 + 7;
int n, m, k, rep[A], sz[A];
vector<int> v[A], b[A];
int find(int u) {
	return rep[u] == u ? u : rep[u] = find(rep[u]);
}
void join(int a, int b) {
	a = find(rep[a]), b = find(rep[b]);
	if (a == b)
		return;
	if (sz[a] < sz[b])
		swap(a, b);
	rep[b] = a, sz[a] += sz[b];
}
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
	    rep[i] = i, sz[i] = 1;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        v[x].pb(y), v[y].pb(x);
        join(x, y);
    }
    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        b[x].pb(y), b[y].pb(x);
    }
    for (int i = 1; i <= n; i++) {
        set<int> st;
        int x = find(i);
        for (auto j : b[i]) {
            int y = find(j);
            if (x == y) st.insert(j);
        }
        for (auto j : v[i]) {
            int y = find(j);
            if (x == y) st.insert(j);
        }
        cout << sz[x] - (int)st.size() - 1 << ' ';
    }
    return 0;
}

Measured memory_bytes: 19660
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 dp[n];
    rep (i, n) dp[i] = 0;
    dp[0] = 1;
    rep (i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        if (a > b) swap(a, b);
        dp[b] -= a + 1;
    }

    s64 ans = dp[0];
    for (int i = 1; i < n; ++i)
    {
        dp[i] += dp[i - 1] + i + 1;
        ans += dp[i];
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 5208
/*author : Yashvardhan
Saturday, June 27, 2020
5:28 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

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

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int a;
	cin >> a;

	cout << a + a * a +  a * a * a << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>
#include<string.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int n;
char s[50][52];
int comp(char s[50][52],int i,int j,int k){
    for(int a=0;a<k+1;a++){
        if(s[i][a]!=s[j][a]) return 1;
    }
    return 0;
}
int main(void){
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        getchar();
        char code[50][52]={0};
        rep(i,n) fgets(s[i],52,stdin);
        //rep(i,n) printf("%s",s[i]);
        rep(i,n){
            int flag=0;
            int len=strlen(s[i])-1;
            //printf("len:%d\n",len);
            code[i][0]=s[i][0];
            int cnt=1;
            for(int j=0;j<len;j++){
                char c=s[i][j];
                //ミス
                if(flag){code[i][cnt++]=s[i][j]; flag=0;}
                switch(c){
                    case 'a': case 'i': case 'u': case 'e': case 'o':
                        flag=1;
                        break;
                    default:break;
                }
            }
        }
        //rep(i,n) printf("%s\n",code[i]);
        int max=0;
        rep(i,n) if(max<strlen(code[i])) max=strlen(code[i]);
        //printf("%d\n",min);
        int ans;
        int flag;
        for(int k=0;k<max;k++){
            flag=1;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    if(comp(code,i,j,k)==0){
                        flag=0; break;
                    }
                }
                if(flag==0) break;
            }
            if(flag){ans=k+1; break;}
        }
        if(flag==0) printf("-1\n");
        else printf("%d\n",ans);
    }
}



Measured memory_bytes: 2048