akhauriyash/Code-Regression huggingface dataset:
import sys;input=sys.stdin.readline
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
    import sys
    mod = pow(10, 9) + 7
    sys.setrecursionlimit(pow(10, 8))

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

from collections import deque
N, = map(int, input().split())
d = [list() for _ in range(N+1)]
d2 = [list() for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

queue=deque([1])
vs = set([1])
vs_bfs = list()
parents = [0] * (N+1)
while queue:
    v = queue.popleft()
    vs_bfs.append(v)
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
        d2[v].append(u)

dp1 = [0 for _ in range(N+1)]
sss = [0 for _ in range(N+1)]
for v in vs_bfs[::-1]:
    t = 1
    ts = []
    for u in d2[v]:
        t = mul(dp1[u], t)
        ts.append(sss[u])
    st = sum(ts)
    sss[v] = st + 1
    for tt in ts:
        t = mul(cmb(st, tt, mod), t)
        st -= tt
    dp1[v] = t
#print(dp1)

dp2 = [0]*(N+1)
for v in vs_bfs:
    if v == 1:
        dp2[v] = dp1[v]
        continue
    p = parents[v]
#    print(dp2[p])
    t = div2(dp2[p], mul(dp1[v], cmb(N-1, sss[v], mod)))
    dp2[v] = mul(mul(dp1[v], t), cmb(N-1, N-sss[v], mod))

#print(dp2)

for x in dp2[1:]:
    print(x)


Measured memory_bytes: 162400
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{	
	string n;
    cin >> n;
    long long sum = 0;
    for(char x : n)  sum += x - '0';
    cout << ( ( sum%9==0 ) ? "Yes" : "No" );
	return 0;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int n, m, q;
vec a, b, c, d;
int res = 0;

void update(vec& v) {
    int rt = 0;

    rep(i, q) {
        if (v[b[i]] - v[a[i]] == c[i]) rt += d[i];
    }

    res = max(res, rt);
}

void dfs(vec v, int prv=1) {
    if (v.size() == n) {
        update(v);
    }
    else {
        for (int i = prv; i <= m; i++) {
            vec v2 = v;
            v2.emplace_back(i);
            dfs(v2, i);
        }
    }
}

int main() {
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    rep(i, q) {
        a[i]--;
        b[i]--;
    }

    vec s;
    dfs(s);

    cout << res << endl;
    return 0;
}

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

int n, m, q;
vector<vector<int> > kouho;
void dfs(int now, vector<int> s){
    if(s.size() == n){
        kouho.push_back(s);
    }
    else {
        for(int i = now;i<=m;i++){
            vector<int> tmp = s;
            tmp.push_back(i);
            dfs(i, tmp);
        }
    }
}
 
int main(void){
    cin>>n>>m>>q;
    vector<vector<int> > v(q, vector<int>(4));
    rep(i, q){
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        --a;--b;
        v[i] = {a, b, c, d};
    }
    vector<int> s;
    dfs(1, s);
    ll ans = 0;
    rep(i, kouho.size()){
        ll tmp = 0;
        rep(j, q){
            int a = v[j][0];
            int b = v[j][1];
            int c = v[j][2];
            int d = v[j][3];
            if(kouho[i][b]-kouho[i][a] == c) tmp+=(ll)d;
        }
        ans=max(ans, tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9872
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


typedef long long int64;
typedef pair<int64, int64> P;


int main() {
    int n;
    int64 ans = 0;
    cin >> n;
    vector<int> x(n);
    vector<int> l(n);
    priority_queue<P, vector<P>, greater<>> pq;

    for (int i=0; i<n; i++) {
        int x,l;
        cin >> x >> l;
        pq.emplace(x+l, x-l);
    }

    int64 pre = INT_MIN;
    while(!pq.empty()) {
        int64 start,stop;
        tie(stop, start) = pq.top(); pq.pop();
        if (start < pre) continue;
//        cout << start << " " << stop << endl;
        ans++;
        pre = stop;
    }

    cout << ans << endl;
}

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

int main(){
  int a[4],b[4];
  int n=0;
  while(cin>>a[n]){
    n++;
    if(n==4)break;
  }

  n=0;

  while(cin>>b[n]){
      n++;
if(n==4)break;
    }
 int  A=a[0]+a[1]+a[2]+a[3];
 int  B=b[0]+b[1]+b[2]+b[3];
  if(A>B){
    cout << A << endl;
  }
if(A<B){
    cout << B << endl;
  }     
 if(A==B){
    cout << A << endl;
  }
    return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

char grid[10][10];
bool done[10][10];
int32_t main(){
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		cin>>grid[i]+1;
	}
	int curx = 1;
	int cury = 1;
	if(grid[1][1]=='.'){
		cout<<"Impossible";
		return 0;
	}
	until(curx==w && cury==h){
		done[cury][curx]=1;
		int p = grid[cury+1][curx]=='#';
		int q = grid[cury][curx+1]=='#';
		if(p&&q){
			cout<<"Impossible";
			return 0;
		}
		if(p){
			cury++;
		}
		if(q){
			curx++;
		}
		if(!(p+q)){
			cout<<"Impossible";
			return 0;
		}
		done[cury][curx]=1;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(!done[i][j] && grid[i][j]=='#'){
				cout<<"Impossible";
				return 0;
			}
		}
	}
	cout<<"Possible";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char b;
    cin >> b;
    if(b == 'A')
    {
        cout << 'T' << endl;
    }
    else if(b == 'T')
    {
        cout << 'A' << endl;
    }
    else if(b == 'C')
    {
        cout << 'G' << endl;
    }
    else if(b == 'G')
    {
        cout << 'C' << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
int main(){
  
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<'\n';
    else cout<<"win"<<'\n';
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N, K; cin >> N >> K;

    int ans = N%K==0 ? 0 : 1;

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int n;
	cin>>n;
	map<string,int> mp;
	int cnt=0;
	for( int i=0; i<n; i++ )
	{
		string a;
		cin>>a;
		mp[a]++;
		if( cnt< mp[a] )
			cnt = mp[a];
	}
	map<string,int>::iterator it;
	for( it=mp.begin();it!=mp.end();it++)
	{
		if( cnt == it->second )
			cout << it->first << endl;
	}
	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k;
  in2(n, k);
  n--;
  k--;
  if(n % k == 0)
    out(n / k);
  else
    out(n / k + 1);
  memi;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator >(const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll w, h, n;
	cin >> w >> h >> n;
	ll l = 0, r = w, d = 0, u = h;
	while (n--) {
		ll a, b, c;
		cin >> a >> b >> c;
		if (c == 1) l = max(a, l);
		else if (c == 2) r = min(a, r);
		else if (c == 3) d = max(b, d);
		else u = min(b, u);
	}
	if (r - l < 0 || u - d < 0) {
		cout << "0" << endl;
		return 0;
	}
	cout << (r - l)*(u - d) << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque


N, M = [int(i) for i in input().split()]
A = []
B = []
for i in range(M):
    l = [int(i) for i in input().split()]
    A.append(l[0])
    B.append(l[1])

# BFS
G = [[] for _ in range(N)]
for i in range(M):
    G[A[i] - 1].append(B[i] - 1)
    G[B[i] - 1].append(A[i] - 1)
# G = [list(set(x)) for x in G]

q = deque([])
ans = [-1] * N
ans[0] = 0
q.appendleft(0)
while(len(q) > 0):
    v = q.pop()
    for nv in G[v]:
        if not ans[nv] == -1:
            continue
        ans[nv] = v
        q.appendleft(nv)

# for i in ans[1:]:
#     if i == -1:
#         print('No')
#         sys.exit()

for i, v in enumerate(ans):
    if i == 0:
        print('Yes')
        continue
    print(v + 1)

Measured memory_bytes: 49544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    vector<string> S(H);
    REP(i,B){
        S[i] = string(A,'0') + string(W-A,'1');
    }
    REP(i,H-B){
        S[B+i] = string(A,'1') + string(W-A,'0');
    }
    REP(i,H)cout << S[i] << "\n";
}

Measured memory_bytes: 4216
#include<iostream>
using namespace std;
int main(){
  int n,point,ans;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    ans=0;

    n/=4;
    for(int i=0;i<n;i++){
      cin >> point;
      ans+=point;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
  int a[3],k,sum=0,max=0;
  cin>>a[0]>>a[1]>>a[2];
  cin>>k;
  for(int i=0;i<3;i++){
    sum+=a[i];
    if(max<a[i]) max=a[i];
  }
  sum=sum-max;
  for(int i=0;i<k;i++){
    max*=2;
  }
  cout<<sum+max<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=5e5+10;
const int maxm=20e5+10;
char s[maxn],t[maxn],all[maxm];
int ns,nt,n;
int bl,br;
int z[maxm];
void Z_function()
{
	z[0]=n;
	bl=br=0;
	for(int i=1;i<n;i++)
	{
		z[i]=0;
		if(i<=br)
		{
			int p=i-bl;
			if(i+z[p]-1<br)
			{
				z[i]=z[p];
			}
			else
			{
				z[i]=min(z[p],br-i+1);
				while(i+z[i]<n&&all[i+z[i]]==all[z[i]])z[i]++;
				bl=i;
				br=i+z[i]-1;
			}
		}
		else
		{
			while(i+z[i]<n&&all[i+z[i]]==all[z[i]])z[i]++;
			bl=i;
			br=i+z[i]-1;
		}
	}
}
int okpos[maxm],fa[maxm];
int tmp[maxm];
inline int getfa(int x){return fa[x]==x?x:getfa(fa[x]);}
void Union(int x,int y)
{
	x=getfa(x),y=getfa(y);
	fa[x]=y;
}
int main()
{
	scanf("%s",s);ns=strlen(s);
	scanf("%s",t);nt=strlen(t);
	while(n<ns+nt-1)
	{
		for(int i=0;i<ns;i++,n++)
			all[n]=s[i];
	}
//	cout<<all<<endl;
	for(int i=nt+n-1;i>=nt;i--)
		all[i]=all[i-nt];
	n+=nt;
	for(int i=0;i<nt;i++)
		all[i]=t[i];
	Z_function();
	ll ans=0,res=0;
//	cout<<all<<endl;
for(int i=0;i<n;i++)fa[i]=i;
	for(int q=nt;q<nt+ns;q++)
	{
		int i=q;
	//	cout<<i<<" "<<z[i]<<endl;
		int p=i-nt;
		if(z[i]>=nt)
		{
			res=0;
			while(z[i]>=nt)
			{
				if(okpos[p]==q)
				{
					printf("-1");
					return 0;
				}
				else if(okpos[p]!=0)
				{
					res+=tmp[getfa(p)];
					Union(p,q-nt);
					break;
				}
				okpos[p]=q;
				Union(p,q-nt);
				res++;
				i+=nt;
				if(i>=nt+ns)
				{
					i=nt+(i-nt)%ns;
				}
				p+=nt;
				p%=ns;
			//	cout<<i<<" "<<p<<endl;
			}
			ans=max(ans,res);
			tmp[q-nt]=res;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 26112
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int len, keta = 0;
        string a, b, c = "";
        cin >> a >> b;
        reverse(a.begin(), a.end());
        reverse(b.begin(), b.end());
        len = max(a.size(), b.size());
        for (int i = 0, size = len - a.size(); i < size; i++) {
            a += '0';
        }
        for (int i = 0, size = len - b.size(); i < size; i++) {
            b += '0';
        }
        for (int i = 0; i < len; i++) {
            c += ((a[i] - '0') + (b[i] - '0') + keta) % 10 + '0';
            keta = ((a[i] - '0') + (b[i] - '0') + keta) / 10;
        }
        if (keta == 1) {
            c += '1';
        }
        reverse(c.begin(), c.end());
        if (c.size() > 80) {
            cout << "overflow\n";
        }
        else {
            cout << c << endl;
        }
    }
    
    return 0;
}

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

int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if(a <= b && b <= c){
        cout << a << " " << b << " " << c << endl;
    }else if(b <= a && a <= c){
        cout << b << " " << a << " " << c << endl;
    }else if(c <= a && a <= b){
        cout << c << " " << a << " " << b << endl;
    }else if(a <= c && c <= b){
        cout << a << " " << c << " " << b << endl;
    }else if(c <= b && b <= a){
        cout << c << " " << b << " " << a << endl;
    }else if(b <= c && c <= a){
        cout << b << " " << c << " " << a << endl;
    }
    return 0;
}


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

const int N = 100010;
const int md = 1e9 + 7;

int n, a[N];
int f[N];
int pos[N];

int pw(int a, int b) {
	int res = 1;
	for (int i = 0; (1LL << i) <= b; ++i) {
		if (b & (1LL << i)) res = 1LL * res * a % md;
		a = 1LL * a * a % md;
	}
	return res;
}

int nCk(int n, int k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return 1LL * f[n] * (1LL * pw(f[k], md - 2) * pw(f[n - k], md - 2) % md) % md;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	f[0] = 1; for (int i = 1; i < N; ++i) f[i] = 1LL * f[i-1] * i % md;
	cin >> n;

	int x = 0, y = 0;
	for (int i = 1; i <= n + 1; ++i) {
		cin >> a[i]; 
		if (pos[a[i]]) x = pos[a[i]], y = i;
		else pos[a[i]] = i;
	}

	for (int k = 1; k <= n + 1; ++k) {
		int ans = (2LL * nCk(n, k - 1) % md + nCk(n - 1, k)) % md;
		//cerr << k << ' ' << ans << endl;
		ans = (ans - nCk(x + n - y, k - 1)) % md;
		ans = (ans - nCk(n - 1, k - 2)) % md;
		if (ans < 0) ans += md;

		cout << ans << endl;
	}
}

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

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

    int  A[N], AD = 0;

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

        if (A[i] % 2 == 0)
        {
            if (A[i] % 3 == 0 || A[i] % 5 == 0)
            {
                ++AD;
            }else
            {
                AD = 0;
                break;
            }   
        }else
        {
            ++AD;
        }
        
        
    }
    
    if (AD > 0)
    {
        cout << "APPROVED";
    }else{
        cout <<  "DENIED";
    }
    

    return 0;
}


Measured memory_bytes: 256
MOD = 1000000007

def main():
    n,m = map(int,input().split())
    al = [False for _ in range(n+1)]
    for i in range(m):
        a = int(input())
        al[a] = True
    
    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    dp[1] = 1 if al[1] == False else 0

    for i in range(2,n+1):
        if not al[i]:
            dp[i] = dp[i-2] + dp[i-1]

    print(dp[n] % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 460824
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,d,r;
	double f;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	cout<<d<<" "<<r<<" ";
	printf("%.8lf\n",f);
	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    string s, t = "keyence";
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        for (int j = i; j <= s.size(); j++) {
            string ss = "";
            for (int k = 0; k < s.size(); k++) {
                if (!(i <= k && k < j)) ss += s[k];
            }
            if (ss == t) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,j,k;
int main()
{
	cin>>a;
	if(a%7==0||a%4==0||a%7%4==0){
		cout<<"Yes";
		return 0;
	}
	for(int i=1;i<=a;i++){
		j=a-i*4;
		k=a-i*7;
		if(j%7==0&&j>=0||k%4==0&&k>=0){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

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

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

    int N; cin >> N;
    string S = to_string(N);
    string x(S.size()+1, '0');
    int ans = 0;
    long long m = 0;
    while (m <= N) {
        if (x.find('7') != string::npos
         && x.find('5') != string::npos
         && x.find('3') != string::npos)
            ans++;

        for (int i = x.size()-1; i >= 0; i--) {
            if (x[i] == '0')
                x[i] = '3';
            else if (x[i] == '3')
                x[i] = '5';
            else if (x[i] == '5')
                x[i] = '7';
            else {
                x[i] = '3';
                continue;
            }
            break;
        }
        
        m = 0;
        long long d = 1;
        for (int i = x.size()-1; i >= 0; i--) {
            m += (x[i]-'0') * d;
            d *= 10;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

struct P {
    int a;
    int b;
};
int main() {
    int n; cin >> n;
    vector<P> red(n);
    vector<P> blue(n);
    rep(i,n) cin >> red[i].a >> red[i].b;
    rep(i,n) cin >> blue[i].a >> blue[i].b;

    sort(ALL(red),[](P a, P b){
        if(a.a==b.a) return a.b > b.b;
        return a.a < b.a;
    });
    sort(ALL(blue),[](P a, P b){
        if(a.a==b.a) return a.b > b.b;
        return a.a < b.a;
    });

    int ans = 0;
    rep(i,n) {
        int now = -1;
        int cnt = -1;
        rep(j,n) {
            if(red[j].a < blue[i].a && red[j].b < blue[i].b) {
                if(red[j].b>cnt) {
                    cnt = red[j].b;
                    now = j;
                }
            }
        }
        if(now!=-1) {
            red[now].a = INF;
            red[now].b = INF;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();

        final int result = a + b >= c ? b + c : a + 2 * b + 1;
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int total = n*n;
        int a = in.nextInt();

        System.out.println(total-a);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}

main(){
  scanf("%d", &size);
  int i;
  for ( i = 1; i <= size; i++ ) scanf("%d", &A[i]);
  
  for ( i = size/2; i >= 1; i-- ) maxHeapify(i);

  for ( i = 1; i <= size; i++ ) {
    printf(" %d", A[i]);
  }
  printf("\n");
  

  
  return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,v,i,s=0,nr;
    vector<ll>a;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>v;
        a.push_back(v);
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            nr=a[i-1]-a[i];
            s+=nr;
            a[i]+=nr;
        }
    }
    cout<<s<<endl;
    a.clear();
}


Measured memory_bytes: 5368
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toInt() }
    val ls = readLine()!!.split(" ").map { it.toInt() }

    var c = 1
    var sum = 0

    ls.forEach{
        sum += it
        if(sum > x) return@forEach
        c++
    }

    println(c)
}

Measured memory_bytes: 37912
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;


int main(){
	ll x,y;
	cin>>x>>y;
	for(ll i=0; i<=1000; i++){
		for(ll j=0; j<=1000; j++){
			ll flag=(i*2)+(j*4);
			if(flag==y && (i+j)==x){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}


Measured memory_bytes: 3628
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-3.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vi p;
  p.pb(INF);
  map<int, int> pos;
  rep(i,1,n+1){
    int tmp;cin>>tmp;
    p.pb(tmp);
    pos[tmp] = i;
  }
  p.pb(INF);
  dump(p);
  dump(pos);

  vi R(n+2, n+1);
  vi R2(n+2, n+1);
  {
    set<int> s1;
    set<int> s2;
    s1.insert(INF);
    s2.insert(INF);
    rep(i, 1, n+2){
      dump(i, s1, s2);
      auto it = s2.begin();
      while (*it<p[i]){
        R2[pos[*it]] = i;
        it = s2.erase(it);
      }

      it = s1.begin();
      while (*it < p[i]){
        R[pos[*it]] = i;
        s2.insert(*it);
        it = s1.erase(it);
      }
      s1.insert(p[i]);
    }
  }
  dump(R);
  dump(R2);

  vi L(n+2, 0);
  vi L2(n+2, 0);
  {
    set<int> s1;
    set<int> s2;
    s1.insert(INF);
    s2.insert(INF);
    rrep(i, 1, n+2){
      dump(i, s1, s2);
      auto it = s2.begin();
      while (*it<p[i]){
        L2[pos[*it]] = i;
        it = s2.erase(it);
      }

      it = s1.begin();
      while (*it < p[i]){
        L[pos[*it]] = i;
        s2.insert(*it);
        it = s1.erase(it);
      }
      s1.insert(p[i]);
    }
  }
  dump(L);
  dump(L2);

  int ans = 0;
  rep(i, 1, n+1){
    ans += p[i]*abs((R2[i]-R[i])*(i-L[i]));
    ans += p[i]*abs((L2[i]-L[i])*(i-R[i]));
    dump(i, ans);
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

vector<string> a;

const int MAXN = 190;

int xb_max[MAXN][MAXN][MAXN][2];
int yb_max[MAXN][MAXN][MAXN][2];

int main(){
	int n, m;
	cin >> n >> m;
	a.resize(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int _q = 0; ; _q++){
		int q = _q & 1;
		for(int xa = n; xa >= 0; xa--){
			for(int ya = m; ya >= 0; ya--){
				for(int xb = xa; xb <= n; xb++){
					if(_q == 0){
						if(ya == m || xb == xa){
							yb_max[xa][ya][xb][q] = m;
						} else if(xb == xa+1){
							yb_max[xa][ya][xb][q] = yb_max[xa][ya+1][xb][q];
							if(ya + 1 < m && a[xa][ya] != a[xa][ya+1]){
								yb_max[xa][ya][xb][q] = ya + 1;
							}
						} else {
							yb_max[xa][ya][xb][q] = min(
								yb_max[xa][ya][xb-1][q],
								yb_max[xa+1][ya][xb][q]);
							if(a[xa][ya] != a[xa+1][ya]){
								yb_max[xa][ya][xb][q] = ya;
							}
						}
					} else {
						int v = yb_max[xa][ya][xb][q^1];
						yb_max[xa][ya][xb][q] = yb_max[xa][v][xb][q^1];
					}
				}
				for(int yb = ya; yb <= m; yb++){
					if(_q == 0){
						if(xa == n || yb == ya){
							xb_max[xa][ya][yb][q] = m;
						} else if(yb == ya + 1){
							xb_max[xa][ya][yb][q] = xb_max[xa+1][ya][yb][q];
							if(xa + 1 < n && a[xa][ya] != a[xa+1][ya]){
								xb_max[xa][ya][yb][q] = xa + 1;
							}
						} else {
							xb_max[xa][ya][yb][q] = min(
								xb_max[xa][ya][yb-1][q],
								xb_max[xa][ya+1][yb][q]);
							if(a[xa][ya] != a[xa][ya+1]){
								xb_max[xa][ya][yb][q] = xa;
							}
						}
					} else {
						int v = xb_max[xa][ya][yb][q^1];
						xb_max[xa][ya][yb][q] = xb_max[v][ya][yb][q^1];
					}
				}
				// merge here
				int cury = ya;
				for(int xb = n; xb >= xa; xb--){
					while(cury < m && xb_max[xa][ya][cury+1][q] >= xb){
						cury++;
					}
					yb_max[xa][ya][xb][q] = max(yb_max[xa][ya][xb][q], cury);
				}
				int curx = xa;
				for(int yb = m; yb >= ya; yb--){
					while(curx < n && yb_max[xa][ya][curx+1][q] >= yb){
						curx++;
					}
					xb_max[xa][ya][yb][q] = max(xb_max[xa][ya][yb][q], curx);
				}
			}
		}
		if(yb_max[0][0][n][q] == m){
			cout << _q << '\n';
			break;
		}
	}
}

Measured memory_bytes: 106752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    ll H,W; cin >> H >> W;

    ll ans = 1000000000000;

    ll s1, s2, s3;
    for(ll w=1; w<W; w++){
        ll res = W-w;
        s1 = w*H;
        s2 = res/2*H;
        s3 = (res-res/2)*H;
        ll tmp = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
        ans = min(ans, tmp);
    }

    for(ll w=1; w<W; w++){
        ll res = W-w;
        s1 = w*H;
        s2 = res*(H/2);
        s3 = res*(H-H/2);
        ll tmp = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
        ans = min(ans, tmp);
    }

    for(ll h=1; h<H; h++){
        ll res = H-h;
        s1 = h*W;
        s2 = W*(res/2);
        s3 = W*(res - res/2);
        ll tmp = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
        ans = min(ans, tmp);
    }

    for(ll h=1; h<H; h++){
        ll res = H-h;
        s1 = W*h;
        s2 = res*(W/2);
        s3 = res*(W - W/2);
        ll tmp = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

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

int main() {
	string s,t,k="Yes",al="abcdefghijklmnpoqrstuvwxyz";
	cin >> s >> t;
	int a=s.size();
	for(int i=0;i<26;i++)
	{
		char u = al.at(i),
		     tb=' ',ta=' ',sb=' ',sa=' ';
		for(int j=0;j<a;j++)
		{
			if(s.at(j)==u)
			{
				ta = t.at(j);
				if(tb != ' '&&ta != tb)
				{
					k = "No";
				}
				tb = ta;
			}
			if(t.at(j)==u)
			{
				sa = s.at(j);
				if(sb != ' '&&sa != sb)
				{
					k = "No";
				}
				sb = sa;
			}
		}
	}
	cout << k << endl;
	return 0;
}


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

long long fac(int k){long long sum = 1;for(int i=1;i<=k;++i)sum *= i;return sum;}
long long per(int n,int r){long long nn,rr;nn=fac(n);rr=fac(r)*fac(n-r);return nn/rr;}

int main(){
    int N;
    cin >> N;
    if(N>=1000){
        cout << "ABD" << endl;
        return 0;
    }else{
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  //パスワード入力
  static Scanner sc = new Scanner(System.in);
  static String pw = sc.next();
  
  //判定
  public static String check(String pw) {
      for (int i=0; i < pw.length()-1; i++) {
      if (pw.substring(i, i+1).equals(pw.substring(i+1, i+2))) {
        return "Bad";
      }
    }
    return "Good";
  }
  
  //結果出力
  public static void main(String[] args) {
    String result = check(pw);
    System.out.println(result);
 }
 
}

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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll res = a[0];
    for(int i=2;i<n;i++) {
        res += a[i/2];
    }
    cout << res << endl;
    return;
} 

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


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

count = 0
ans = 0
for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count == 3:
        ans += 1

if ans > 0:
    print("Yes")
else:
    print("No")

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

const int INF = 1001001001;

int main(){
    int n;
    cin>>n;
    int ai;
    int i;
    int count=0;
    rep(i,n){
        cin>>ai;
        if((i+1)%2==1&&ai%2==1)count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3616
import numpy as np

N , K = map(int, input().split())

m = np.zeros((3*K, 3*K), dtype=int)
L = 2 * K
o = 0

for _ in range(N):
	x, y, c = input().split()
	x , y = int(x) % L, int(y) % L
	t = c=='W'
	m[x, y] += 1 - 2 * t
	o += t

for _ in range(2):
	m[L:] = m[:K]
	m = np.cumsum(m,axis=0)
	m[:L] = m[K:] - m[:L]
	m = m.T

m = m[:L,:L]
print(o + (m + np.roll(np.roll(m, K, axis=0), K, axis=1)).max())


Measured memory_bytes: 153084
#include<iostream>
using namespace std;
int main() {
	int fib[50];
	fib[0] = 1;
	fib[1] = 1;
	int n; cin >> n;
	for (int i = 2; i < n + 1; i++){
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	cout << fib[n] << endl;
}

Measured memory_bytes: 3080
L = gets.to_i
N = L.bit_length
ans = []
(1...N).each do |i|
    ans.push([i, i+1, 2**(i-1)])
    ans.push([i, i+1, 0])
end

now = 2**(N-1)-1
(N-1).downto(1) do |i|
    break if now == L-1
    gain = 2**(i-1)
    if now + gain <= L-1
        ans.push([i, N, now+1])
        now += gain
    end
end
if now < L-1
    ((now+1)..(L-1)).each do |v|
        ans.push([1, N, v])
    end
end

M = ans.length
puts [N, M].join(' ')
ans.each do |arr|
    puts arr.join(' ')
end

Measured memory_bytes: 1788
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
 
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
 
public class Main {
    
    public static BufferedReader br;
    public static StringTokenizer sto;
    
    public static void main(String args[] ) throws Exception {
        StringBuffer str = new StringBuffer();
        PrintWriter pw=new PrintWriter(System.out);
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        char[] c = br.readLine().toCharArray();
        int r=0;
        for(int i=0;i<n;i++){
            if(c[i]=='R')
                r++;
        }
        int ans=0;
        for(int i=0;i<r;i++){
            if(c[i]=='W')
                ans++;
        }
        str.append(ans);
        pw.println(str.toString());
        
        pw.close();
    }
     
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    public static int[] arrayInt(int n) throws Exception{
       sto = new StringTokenizer(br.readLine());
       int[] newarray = new int[n];
       for(int i=0;i<n;i++){
           newarray[i] = Integer.parseInt(sto.nextToken());
       }
       return newarray;
    }
    
    public static long[] arrayLong(int n) throws Exception{
       sto = new StringTokenizer(br.readLine());
       long[] newarray = new long[n];
       for(int i=0;i<n;i++){
           newarray[i] = Long.parseLong(sto.nextToken());
       }
       return newarray;
    }
   
   
   public static double nextDouble() throws Exception{
       return Double.parseDouble(br.readLine());
   }
   
   public static long nextLong() throws Exception{
       return Long.parseLong(br.readLine());
   }
   
   
   public static int nextInt() throws Exception{
       return Integer.parseInt(br.readLine());
   }
   
}

Measured memory_bytes: 36760
import sys
input = sys.stdin.readline
def l(): return [int(a) for a in input().split(" ")] 
ka = l()
lis = {}
saku = []
for i,a in zip(range(ka[0]),l()):
  lis[i+1] = a
for _ in range(ka[1]):
  q = l()
  maxindex = []
  a = [[lis[a],a] for a in q if a in lis]
  maxv = max(a)
  for b in a:
    if maxv[0] == b[0]:
      maxindex.append(b)
  q.pop(q.index(maxv[1]))
  if len(maxindex) != 1:
    for m in maxindex:
      q.append(m[1])
  for a in q:
    saku.append(a)
saku = set(saku)
print(len([a for a in lis if a not in saku]))
  
  
  

Measured memory_bytes: 98196
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int x,y;
  cin>>x>>y;
  if(x==0 || y==0){
    if(y>x)
      cout<<y+abs(x)<<endl;
    else
      cout<<abs(y)+x+1<<endl;
  }else if(x*y>0){
    if(x<y)
      cout<<y-x<<endl;
    else
      cout<<x-y+2<<endl;
  }else if(x*y<0)
    cout<<abs(abs(y)-abs(x))+1<<endl;
}

Measured memory_bytes: 3572
#include<stdio.h>
int main(){
    int a,b, k;
    scanf("%d %d %d", &a, &b, &k);
    int d[101];

    int n = 0;
    for(int i=1; i<101; i++){
        if(a%i==0 && b%i==0){
            d[n]=i;
            n++;
        }
    }
    printf("%d\n", d[n-k]);
    return 0;
}

Measured memory_bytes: 128
while True:
    S = input()
    if S==".":
        break
    a = [-1]
    b = [-1]
    ans = "yes"
    for i in range(len(S)):
        s = S[i]
        if s=="(":
            a.append(i)
        if s=="[":
            b.append(i)
        if s==")":
            if len(a)==1 or a[len(a)-1]<b[len(b)-1]:
                ans = "no"
                break
            else:
                del a[len(a)-1]
        if s=="]":
            if len(b)==1 or b[len(b)-1]<a[len(a)-1]:
                ans = "no"
                break
            else:
                del b[len(b)-1]
    if len(a)!=1 or len(b)!=1:
        ans = "no"
    print(ans)


Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    ll mod = 1e9 + 7;
    int n, m;
    cin >> n >> m;
    ll x[n], y[m];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }

    ll ans = 0;
    ll totalX = 0;
    for (int i = 0; i < n; i++) {
        totalX += x[i] *(i - (n - i - 1));
        totalX %= mod;
    }
    ll totalY = 0;
    for (int i = 0; i < m; i++) {
        totalY += y[i] *(i - (m - i - 1));
        totalY %= mod;
    }
    cout << (totalX * totalY) % mod << endl;

    return 0;
}


Measured memory_bytes: 1792
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//うーん

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[1 << 18];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int n = (1 << N);
	int S[1 << 18];
	rep(i, (1 << N)) S[i] = getint();
	pakuri_sort(n, S);
	int A0[(1 << 16) + 1], A1[(1 << 16) + 1], A2[1 << 17];
	A0[0] = S[n - 1];
	int OK = 1;
	rep(i, N - 1) {
		int p = n - 1;

		if (i % 2 == 0) {
			for (int j = (1 << i) - 1; j >= 0; j--) {
				while (p >= 0 && S[p] >= A0[j]) p--;
				if (p < 0) {
					OK = 0;
					break;
				}
				A1[j] = S[p];
				S[p] = 1e9;
				p--;
			}
			if (!OK) break;

			A0[1 << i] = 1e9;
			A1[1 << i] = 1e9;
			int p1 = 0, p2 = 0;
			rep(k, 1 << (i + 1)) {
				if (A0[p1] < A1[p2]) A2[k] = A0[p1++];
				else A2[k] = A1[p2++];
			}
		}
		else {
			for (int j = (1 << i) - 1; j >= 0; j--) {
				while (p >= 0 && S[p] >= A2[j]) p--;
				if (p < 0) {
					OK = 0;
					break;
				}
				A1[j] = S[p];
				S[p] = 1e9;
				p--;
			}
			if (!OK) break;

			A1[1 << i] = 1e9;
			A2[1 << i] = 1e9;
			int p1 = 0, p2 = 0;
			rep(k, 1 << (i + 1)) {
				if (A2[p1] < A1[p2]) A0[k] = A2[p1++];
				else A0[k] = A1[p2++];
			}
		}
	}
	int i = N - 1;
	int p = n - 1;
	if (i % 2 == 0) {
		for (int j = (1 << i) - 1; j >= 0; j--) {
			while (p >= 0 && S[p] >= A0[j]) p--;
			if (p < 0) {
				OK = 0;
				break;
			}
			p--;
		}
	}
	else {
		for (int j = (1 << i) - 1; j >= 0; j--) {
			while (p >= 0 && S[p] >= A2[j]) p--;
			if (p < 0) {
				OK = 0;
				break;
			}
			p--;
		}
	}

	if (OK) printf("Yes");
	else printf("No");

	Would you please return 0;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int result = 0;
        int ans = 0;
        while (result < n - 2) {
            result = s.indexOf("ABC", result);
            if (result != -1) {
                ans++;
                result++;
            }else{
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <fstream>

int main(){
    int hit, out, score, data_set_num;
    std::string event, str;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
            out = 0;
            --data_set_num;
        }
    }

    return 0;
}

Measured memory_bytes: 3180
a,b,c = gets.chomp.split.map(&:to_i)
sum = a + b + c
times = 0
i = 0
while a%2==0 && b%2==0 && c%2==0
  i = a
  a = b/2 + c/2
  b = i/2 + c/2
  c = sum - i - b
  times += 1
  if sum == a*3
    times = -1
    break
  end
end

puts times

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

#define endl "\n"
#define INF 9e18
#define int long long
#define uint unsigned long long
#define MOD (int) (1e9 + 7)
#define deb(x) cout << #x << " => " << x << "\n"
#define deba(x) cout << #x << "\n"; for (auto a : x) cout << a << " "; cout << "\n";
#define debm(x) cout << #x << "\n"; for (auto a : x) {for(auto b : a) cout << b << " "; cout << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m;
    while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    } return res;
}

int merge(vector<int> &a, int low, int mid, int high) {
    vector<int> temp;
    int i = low, j = mid + 1;
    int count = 0;
    while (i <= mid and j <= high) {
        if (a[i] <= a[j]) {
            temp.push_back(a[i]);
            i++;
        } else {
            temp.push_back(a[j]);
            j++;
            count += mid - i + 1;
        }
    }
    while (i <= mid) {
        temp.push_back(a[i]);
        i++;
    }
    while (j <= high) {
        temp.push_back(a[j]);
        j++;
    }
    for (int i = 0, j = low; j <= high; j++, i++) {
        a[j] = temp[i];
    }
    return count;
}

int mergeSort(vector<int> &arr, int low, int high) {
    int count = 0;
    if (low < high) {
        int mid = (low + high) / 2;
        count += mergeSort(arr, low, mid);
        count += mergeSort(arr, mid + 1, high);
        count += merge(arr, low, mid, high);
    }
    return count;
}

int32_t main() {
    fastio;
    // int t; cin >> t;
    // while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> arr(n);
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
        }
        int count = mergeSort(arr, 0, arr.size() - 1);
        vector<int> b = arr;
        for (auto a : arr) {
            b.push_back(a);
        }
        int mergeCount = merge(b, 0, n - 1, 2 * n - 1);
        int modInv = (MOD + 1) / 2;
        int res = ((k * count) % MOD + (((k * (k - 1)) % MOD) * ((mergeCount * modInv) % MOD)) % MOD) % MOD;
        cout << res << endl;
    // }
    return 0;
}


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

using namespace std;

const int N=1001;

int main()
{
    string s1,s2;

    while(cin>>s1>>s2)
    {
        int n=s1.length(),m=s2.length();
        vector<vector<int> > dp(N,vector<int>(N));

        for(int i=0;i<=n;i++)
        {
            dp[i][0]=i;
        }
        for(int i=0;i<=m;i++)
        {
            dp[0][i]=i;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(s1[i-1]==s2[j-1])
                {
                    dp[i][j]=dp[i-1][j-1];
                }else
                {
                    dp[i][j]=min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]))+1;
                }
            }
        }
        cout<<dp[n][m]<<endl;
    }

    return 0;
}



Measured memory_bytes: 6924