akhauriyash/Code-Regression huggingface dataset:
from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = deque(), deque()

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L.appendleft(Query[i][2])
      else: R.append(Query[i][2])
    else:
      if count % 2 == 0: R.append(Query[i][2])
      else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int n;
    cin >> n;
    string s[n];
    int p[n];
    rep(i,n){
        cin >> s[i] >> p[i];
    }
    vector<pair<string, int>> a(n);
    rep(i,n){
        a[i] = make_pair(s[i], p[i]);
    }
    sort(a.begin(), a.end());
    vector<pair<int, int>> b;
    pair<int, int> c;
    rep(i,n){
        if(i!=0 && b.size()!=0 && a[i].first!=a[i-1].first){
            sort(b.begin(), b.end(), greater<pair<int,int> >());
            rep(k,b.size()){
                cc(b[k].second);
            }
            b={};
        }
        rep(j,n){
            if(a[i].first==s[j] && a[i].second==p[j]){
                c=make_pair(a[i].second, j+1);
                b.push_back(c);
            }
        }
    }
    sort(b.begin(), b.end(), greater<pair<int,int> >());
    rep(k,b.size()){
        cc(b[k].second);
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import math
import sys
from collections import defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect
from heapq import heappop, heappush
from fractions import gcd
import copy


def next_line():
    return input()


def next_int():
    return int(input())


def int_ar():
    return list(map(int, input().split()))


def int_ar_mul(size):
    return [int(input()) for _ in range(size)]


def str_ar(size):
    return [input() for _ in range(size)]


def ints():
    return map(int, input().split())


def strs():
    return input().split()


def main():
    alp = "zabcdefghijklmnopqrstuvwxy"
    n = next_int()
    str = ""
    while n > 0:
        str = alp[n % 26] + str
        if n % 26 == 0:
            n -= 26
        n //= 26
    print(str)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77316
import sys
import numpy as np
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    N, K = map(int, input().split())
    A = list(map(int, input().rstrip().split()))
    for i in range(K, N):
        if A[i - K] < A[i]:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


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

using namespace std;

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    for ( int j = N - 1; j >= i; j-- ) {
      if ( A[j].value < A[j - 1].value) {
        swap(A[j], A[j - 1]);
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    int minj = i;
    for ( int j = i; j < N; j++ ) {
      if ( A[j].value < A[minj].value ) minj = j;
    }
    swap(A[i], A[minj]);
  }
}

void print_cards(struct Card A[], int N) {
  for ( int i = 0; i < N; i++) {
    if ( i > 0 ) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for (int i = 0; i < N; i++) C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print_cards(C1, N);
  cout << "Stable" << endl;

  print_cards(C2, N);
  if ( isStable(C1, C2, N) ) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template <typename T> class SlideMin
{
public:
    vector<int> deq;
    vector<T> res;
    int n,k;
    SlideMin(vector<T> Array, int sz){
        n = (int)Array.size(), k = sz;
        deq.resize(n), res.resize(n);
        int s = 0, t = 0;
        rep(i,n){
            while(s < t && Array[deq[t-1]] <= Array[i]){
                t--;
            }
            deq[t++] = i;
            res[i] = Array[deq[s]];
            if(deq[s] == i-k+1){
                s++;
            }
        }
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,K;
    cin >> n >> m >> K;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    SlideMin<ll> st(a, m);
    rep(i,K-1){
        vl b(n, -INF);
        srep(j,1,n){
            cmx(b[j],st.res[j-1]+(i+2)*a[j]);
        }
        st = SlideMin<ll>(b, m);
    }
    cout << *max_element(all(st.res)) << "\n";
    return 0;
}


Measured memory_bytes: 4976
from collections import Counter
from itertools import combinations


n = int(input())
s = Counter([input()[0] for _ in range(n)])

choices = combinations([x for x in s.keys() if x[0] in 'MARCH'], 3)

if not choices:
    print(0)
    exit()

ans = 0
for choice in choices:
    tmp = 1
    for key in choice:
        tmp *= s[key]
    ans += tmp

print(ans)


Measured memory_bytes: 4224
x, y = map(int, input().split())

# 全部亀でもならない合計足数に足りない
if y > x * 4:
    print('No')
# 全部鶴でも合計足数をはみ出す
elif y < x * 2:
    print('No')
# 足が奇数
elif y % 2 == 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 9164
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  ll k;
  cin>>k;
  int i;
  int counter=0;
  for(i = 0; i<s.size(); i++){
    if(s[i]=='1')counter++;
    else break;
  }
  if(k<=counter) cout<<1<<endl;
  else if(s.size() == counter) cout<<1<<endl;
  else cout<<s[counter]<<endl;
  
  return 0;
}


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

using namespace std;

int main(){
  int N,M; cin>>N>>M;
  vector<int> A(N,0);
  for(int i=0;i<M;i++){
    int a,b; cin>>a>>b;
    A[a-1]++; A[b-1]++;
  }

  for(int i=0;i<N;i++){
    cout<<A[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=2001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    ll ok=n-1,ng=-1;
    while(ok-ng>1){
        bool able=true;
        ll md=(ok+ng)/2;
        ll sum=v[md];
        rep(j,n)if(j!=md){
            if(v[j]>sum*2)able=false;
            sum+=v[j];
        }
        if(able)ok=md;
        else ng=md;
    }
    out(n-ok);
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

#define north 0
#define west 1

pair<int,int> fraction(pair<int,int> a, pair<int,int> b){
	// cout<<a.first<<"/"<<a.second<<endl;
	// cout<<b.first<<"/"<<b.second<<endl;
	a.first = a.first*b.second + b.first*a.second;
	a.second *= b.second;
	// cout<<"first "<<a.first*b.second <<" "<<b.first*a.second<<endl;
	int gcd = __gcd(a.first, a.second);
	// cout<<a.first<<"/"<<a.second<<endl;
	// cout<<"gcd "<<gcd<<endl;
	a.second /= gcd;
	a.first  /= gcd;
	// cout<<a.first<<"/"<<a.second<<endl;
	return a;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		string str;
		vector<int> nw;
		cin>>str;
		
		if(str == "#") break;
		
		for(int i = 0; i < str.size();){
			if(str[i] == 'n'){
				nw.push_back(north);
				i += 5;
			} else {
				nw.push_back(west);
				i += 4;
			}
		}
		
		pair<int,int> ans = {0,1};
		for(int i = nw.size()-1, ni = 1; i >= 0; i--, ni *= 2){
			// cout<<i<<" "<<nw[i]<<endl;
			if(i == nw.size()-1){
				if(west == nw[i]) ans.first = 90;
			}
			else {
				if(west == nw[i]){
					ans = fraction(ans,make_pair(90,ni));
				} else {
					ans = fraction(ans,make_pair(-90,ni));
				}
			}
		}
		cout<<ans.first;
		if(ans.second != 1)cout<<"/"<<ans.second;
		
		cout<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int> 
#define pii pair<int,int>
const int N = 2e5 +5;
int dp[N],n;
int pow(int a,int n,int mod) {
	int y=  1;
	for (;n;n/=2) {
		if (n&1) y = (ll)y*a%mod;
		a = (ll)a*a%mod;
	}
	return y;
}
void solve() {
	cin >> n;
	ll ans = 0;
	vector<pii> v[2];
	for (int i = 0,pos,l,r; i <n; i++) {
		cin >> pos >> l >> r;
		ans += min(l,r);
		if (l >= r) v[0].pb({l-r,pos});
		else v[1].pb({r-l,pos});
	}
	sort(v[0].begin(),v[0].end(),[&](pii a,pii b) {
		if (a.fi != b.fi) return a > b;
		else return a.se < b.se;
	});
	sort(v[1].begin(),v[1].end(),[&](pii a,pii b) {
		if (a.fi != b.fi) return a > b;
		else return a.se > b.se;
	});
	set<int> s;
	for (int i = 1; i <= n; i++) s.insert(i);
	for (auto i : v[0]) {
		int val = i.fi, pos = i.se;
		auto it = s.upper_bound(pos);
		if (it == s.begin()) continue;
		it--;
		s.erase(it);
		ans += i.fi;
	}
	s.clear();
	for (int i = 1; i <= n; i++) s.insert(i);
	for (auto i : v[1]) {
		int val = i.fi, pos = i.se;
		auto it = s.upper_bound(pos);
		if (it == s.end()) continue;
		s.erase(it);
		ans += i.fi;
	}
	cout << ans<<'\n';
}
main(){
	ios::sync_with_stdio(0);  
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	
	
}

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> cnt;
	cnt.resize(n);

	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;

		++cnt[x - 1];
	}

	sort(cnt.begin(), cnt.end());

	vector<int> pre;
	pre.resize(n + 1);

	for(int i = 0; i < n; ++i) {
		pre[i + 1] = pre[i] + cnt[i];
	}

	int ans = n;
	int i = n;

	for(int k = 1; k <= n; ++k) {
		while(1) {
			bool ok = [&] (int x) {
				while(i >= 1 && cnt[i - 1] >= x) {
					--i;
				}

				int sum = pre[i] + (n - i) * x;

				return (sum >= k * x);
			} (ans);

			if(ok) {
				break;
			}

			--ans;
		}

		cout << ans << '\n';
	}

	return 0;

}


Measured memory_bytes: 3200
#include <stdio.h>
#define TAKARA_MAX 1000
#define WEIGHT_MAX 1000

int main() {
  int W, N;
  int i, w, p;
  int value[TAKARA_MAX+1][WEIGHT_MAX+1];
  int newValue;
  struct Takara {
    int price;
    int weight;
  } t[TAKARA_MAX+1];

  int c;

  c = 1;
  while(1) {
    scanf("%d", &W);
    if(W == 0) break;
    scanf("%d", &N);
    for(i = 1; i <= N; i++) {
      scanf("%d,%d", &t[i].price, &t[i].weight);
    }

    for(i = 0; i <= W; i++) value[0][i] = 0;
    for(i = 0; i <= N; i++) value[i][0] = 0;

    for(i = 1; i <= N; i++) {
      for(w = 1; w <= W; w++) {
	p = w - t[i].weight;
	if(p < 0) {
	  value[i][w] = value[i-1][w];
	  continue;
	}
	newValue = value[i-1][p] + t[i].price;
	if(newValue > value[i-1][w]) value[i][w] = newValue;
	else                         value[i][w] = value[i-1][w];
      }
    }

    /*for(i = 0; i <= N; i++) {
      for(w = 0; w <= W; w++) {
	printf("%2d ", value[i][w]);
      }
      printf("\n");
      }*/

    printf("Case %d:\n", c);
    printf("%d\n", value[N][W]);
    for(i = W-1; i >= 0; i--) {
      if(value[N][i] != value[N][W]) {
	printf("%d\n", i+1);
	break;
      }
    }
    c++;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0, i = 0;
    while (i < n) {
        ans++;
        i++;
        while (i < n && a[i-1] == a[i]) i++;
        if (i == n) break;
        bool inc = a[i-1] < a[i];
        i++;
        while (i < n && (inc && a[i-1] <= a[i] || !inc && a[i-1] >= a[i])) i++;
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
	long long a,b,c;
	int n;cin >> n;
	
	if(n==1) cout << 1;
	else if(n==0) cout << 2;
	else
	{
		a=2;b=1;
		for(int i=2;i<=n;i++)
		{
			c=a+b;
			a=b;b=c;
		}	
		cout << c;
	}
	
	return 0;
}

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

long calc(long money){
    if(money-500 >= 0){
        cnt500++;
        calc(money-500);
    }
    else return money;
}

int calc5(long money5){
    if(money5-5 >= 0){
        cnt5++;
        calc5(money5-5);
    }
    else return 0;
}

int main(){
    long x,res,ans;
    cin >> x;
    res = calc(x);
    calc5(res);
    ans = cnt500*1000+cnt5*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define vpi vector<pair<int,int>>
#define w(t) int t;cin>>t;while(t--)
#define pi pair<int,int>
#define mii map<int,int>
#define pb push_back
#define ff first
#define ss second
#define FOR(i,t,n) for(int i=t;i<n;i++)
#define SCI(x)  scanf("%d",&x)
#define SCL(x) scanf("%lld",&x)

int main()
{

	int a;
	double b;
	cin>>a>>b;
	double ans = a*b;
	int ans_ = floor(ans);
	cout<<ans_<<endl;

}

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

vector<int>to[200005];
vector<int>ans;

void dfs (int v, int p = -1){
	for(int u: to[v]){
		if(u == p)continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main(){
	/*intput*/
	int n, q;	cin >> n >> q;
	for(int i = 0; i < n -1; i++){
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	for(int i = 0; i < q; i++){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	/*calculaiton*/
	dfs(0);
	/*output*/
	for(int i =0; i < n; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 23424
s = gets.chomp
t = gets.chomp

h = {}
g = {}
s.size.times do |i|
  if h[s[i]]
    if h[s[i]].count(t[i]) == 0
      h[s[i]] << t[i]
    end
  else
    h[s[i]] = [t[i]]
  end
  if g[t[i]]
    if g[t[i]].count(s[i]) == 0
      g[t[i]] << s[i]
    end
  else
    g[t[i]] = [s[i]]
  end
end
puts h.flatten.flatten == g.invert.flatten.flatten ? 'Yes' : 'No'

Measured memory_bytes: 2632
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2e5;

vector<int> f[SIZE], b[SIZE];
vector<int> ans(SIZE, 0);
vector<bool> vis(SIZE, false);

void dfs(int node, int &comp, vector<int> &temp) {
    if (vis[node])
        return;
    vis[node] = true;
    temp.push_back(node);
    comp++;
    ans[node] -= (f[node].size() + 1);

    for (auto adj : f[node]) {
        dfs(adj, comp, temp);
    }
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        f[a].push_back(b);
        f[b].push_back(a);
    }

    for (int i = 0; i < k; i++) {
        int c, d;
        cin >> c >> d;
        b[c].push_back(d);
        b[d].push_back(c);
    }

    for (int i = 1;i <= n; i++) {
        if (!vis[i]) {
            int comp = 0;
            vector<int> temp;
            dfs(i, comp, temp);
            sort(temp.begin(), temp.end());
            for (auto x : temp) {
                ans[x] += comp;

                int block = 0;
                for (auto p : b[x]) {
                    if (binary_search(temp.begin(), temp.end(), p)) {
                        block++;
                    }
                }
                ans[x] -= block;
            }

        }
    }

    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 21200
N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))

Cs = []

if sum(As) < sum(Bs):
  print(-1)
  exit()

cnt = 0
ms = 0
ps = 0
for i in range(N):
  Cs.append(As[i]-Bs[i])
  if As[i]-Bs[i] < 0:
    cnt += 1
    ms += Bs[i] - As[i]
    
if cnt == 0:
  print(cnt)
  exit()
  
Cs.sort()
i = 0
while ps < ms:
  i += 1
  ps += Cs[-i]
  
print(cnt+i)

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

INF = 10**17

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

dp = [[-INF]*3 for _ in range(N)]

for i, a in enumerate(A):
    if i == 0:
        dp[i][2] = a
    elif i == 1:
        dp[i][0] = max(a, dp[i-1][1])
    elif i == 2:
        dp[i][1] = a
        dp[i][2] = dp[0][2] + a
    elif (i+1)%2 == 0:
        dp[i][0] = max(dp[i-3][2], dp[i-2][0]) + a
    else:
        dp[i][1] = max([dp[i-4][2], dp[i-3][0], dp[i-2][1]]) + a
        dp[i][2] = dp[i-2][2] + a

if N%2 == 0:
    ans = dp[N-1][0]
    if N > 1:
        ans = max(ans, dp[N-2][2])
else:
    ans = dp[N-1][1]
    if N > 1:
        ans = max(ans, dp[N-2][0])
    if N > 2:
        ans = max(ans, dp[N-3][2])
    # tmp = 0
    # for i in reversed(range(N)):
    #     if i%2 == 0 and i >= 2:
    #         tmp += A[i]
    #         ans = max(ans, dp[i-2][1]+tmp)

print(ans)

Measured memory_bytes: 112448
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
/*
signed main(){
  int a,b;
  cin>>a>>b;
  if(a<=5) cout<<0<<endl;
  else if(a<=12) cout<<b/2<<endl;
  else cout<<b<<endl;
  return 0;
}
*/
/*
signed main(){
  int r,d,x;
  cin>>r>>d>>x;
  lp(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
  return 0;
}
*/
int a[100010];
signed main(){
  int n,m;
  cin>>n>>m;
  lp(i,m){
    int l,r;
    cin>>l>>r;
    a[l]++;
    a[r+1]--;
  }
  int ans=0;
  lp(i,100010){
    if(i==0) continue;
    a[i]+=a[i-1];
    if(a[i]==m) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380




int main()
{
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	if ((n % 10 == 7) || ((n / 10) % 10 == 7) || ((n / 100) % 10 == 7))
	{
		cout << "Yes"
			;
	}
	else
	{
		cout << "No";
	}
	return 0;
}

// 9

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

string S;
  cin>>S;
  
  if(S=="ABC"){cout<<"ARC"<<endl;}
  else{
    cout<<"ABC"<<endl;
  }
  
  
}



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

int main () {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, D;
  int ans = 0;
  int cnt = 0;

  cin >> N >> D;

  while(ans < N){
    ans += 2* D + 1;
    cnt++;
  }
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> xv(n);
    vector<int> yv(n);
    vector<int> hv(n);
    rep(i, n) {
        cin >> xv[i] >> yv[i] >> hv[i];
    }
    rep(i, 101) {
        rep(j, 101) {
            int h = 0;
            rep(k, n) {
                if (hv[k] != 0) {
                    h = hv[k] + abs(xv[k] - i) + abs(yv[k] - j);
                }
            }
            bool ok = true;
            rep(k, n) {
                if (max(h - abs(xv[k] - i) - abs(yv[k] - j), 0) != hv[k]) {
                    ok = false;
                    break;
                } 
            }
            if (ok) {
                cout << i << " " << j << " " << h << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    rep(i,n-1)a[i+1] += a[i];
    int ans = LINF;
    loop(i,2,n-1){//[0,i)[i,n)に分割
        int x = a[i-1];//P+Q
        int y = a[n-1] - a[i-1];//R+S
        int p = lower_bound(all(a),x/2) - a.begin();
        int q = lower_bound(all(a),a[i-1]+y/2) - a.begin();
        //cout << p << " " << q << endl;
        for(int s = p-1; s <= p+1; s++)for(int t = q-1; t <= q+1; t++){
            //[0,s)[s,i)[i,t)[t,n)に分割
            if(0 < s && s < i && i < t && t < n){
                vi v;
                v.push_back(a[s-1]);
                v.push_back(a[i-1]-a[s-1]);
                v.push_back(a[t-1]-a[i-1]);
                v.push_back(a[n-1]-a[t-1]);
                sort(all(v));
                ans = min(ans, v.back()-v.front());
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  vector<int64_t> p(N);
  N_TIMES(n, N) { cin >> p[n]; }

  vector<long double> e(N);
  N_TIMES(n, N) {
    e[n] = (1.0 + p[n]) / 2.0;
  }

  vector<long double> s(N + 1);
  s[0] = 0.0;
  N_TIMES(n, N) {
    s[n + 1] = s[n] + e[n];
  }

  long double max_e = 0.0;
  for (uint64_t i = K; i <= N; ++i) {
    max_e = max(max_e, s[i] - s[i - K]);
  }
  cout << fixed << setprecision(12) << max_e << endl;

  return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[4];
    for(int i=1;i<4;i++)
        a[i]=10;
    int N,M,index,num,bad=0;
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        cin>>index>>num;
        if(a[index]!=10 && a[index]!=num)
            bad=1;
        a[index]=num;
    }
    if(N==1)
        if(a[1]==10)
            a[1]=0;
    if(N==2){
         if(a[1]==10)
            a[1]=1;
        if(a[2]==10)
            a[2]=0;
    }

    if(N==3){
        if(a[1]==10)
            a[1]=1;
        if(a[2]==10)
            a[2]=0;
        if(a[3]==10)
            a[3]=0;
    }
    if(N!=1 && a[1]==0)
        bad=1;
    if(bad)
        cout<<-1;
    else{
        if(N==1)
            cout<<a[1];
        if(N==2)
            cout<<a[1]*10+a[2];
        if(N==3)
            cout<<a[1]*100+a[2]*10+a[3];
    }
}


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

int main() {
    int n;
    scanf("%d", &n);
    bitset<13> s;
    bitset<13> h;
    bitset<13> c;
    bitset<13> d;
    for (int i = 0; i < n; i++) {
        int x;
        char suit;
        cin >> suit >> x;
        x--;
        switch (suit) {
            case 'S':
                s.set(x,1);
                break;
            case 'H':
                h.set(x,1);
                break;
            case 'C':
                c.set(x,1);
                break;
            case 'D':
                d.set(x,1);
                break;
            default:
                break;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (!s.test(i)) {
            printf("S %d\n", i+1);
        }
    }
    for (int i = 0; i < 13; i++) {
        if (!h.test(i)) {
            printf("H %d\n", i+1);
        }
    }
    for (int i = 0; i < 13; i++) {
        if (!c.test(i)) {
            printf("C %d\n", i+1);
        }
    }
    for (int i = 0; i < 13; i++) {
        if (!d.test(i)) {
            printf("D %d\n", i+1);
        }
    }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
int main()
{
       int n,k,q;
       cin>>n>>k>>q;
       int a[n];
       memset(a,0,sizeof a);
       fri(i,0,q){
              int xx;
              cin>>xx;
              --xx;
              a[xx]++;
       }
       int sum = 0;
       string ans[n];
       fri(i,0,n){
              int xx = q-a[i];
              if(k-xx<=0){
                     ans[i] = "No";
              }
              else{
                     ans[i] = "Yes";
              }
       }
       fri(i,0,n){
              cout<<ans[i]<<endl;
       }
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long inf = 1000000001; // const 書き換え禁止

int main(void){
    int x,n;
    cin >> x >> n;
    set<int> values;
    rep(i,n){
        int k;
        cin >> k;
        values.insert(k);
    }  

    int diff = inf;
    int ans = inf;
    for(int i = -2000;i <= 2000; i++){
        if(values.count(i)) continue;
        int di = abs(x - i);
        if(di < diff){
            diff = di;
            ans = i;
        }
    }
    cout << ans << endl;
}

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

int main(){
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string k; cin>>k;
	if(k==s) cout<<a-1<<" "<<b<<endl;
	else cout<<a<<" "<<b-1<<endl;
}

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

int main()
{
    string a;
    int n,l;
    cin>>n;
    cin>>a;
    l=a.length();
    if(l>n)
    {
       for(int i=l-1;i>n-1;i--)
       {
           a.erase(i);
       }
       cout<<a<<"..."<<endl;
    }
    else
    {
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main() {
	int n, m, k, a, ans = 0, likeNum[30] = {};
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%d", &k);
		for (int i = 0; i < k; i++) {
			scanf("%d", &a);
			likeNum[a - 1]++;
		}
	}
	for (int i = 0; i < m; i++) {
		if (likeNum[i] == n) {
			ans++;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
//
// Created by kuroneko on 2019-07-06.
//

using namespace std;

#include <iostream>
#include <vector>
#include <cmath>
#include <string>

typedef long long ll;
int INF = 1000000007;

int main() {
    ll R, D, x; cin >> R >> D >> x;

    for (int i = 0; i < 10; i++) {
        x = R * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      System.out.println(n * (n + 1) / 2);
    } finally {
      scanner.close();
    }
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n, x, a[N];
int main() {
    cin >> n >> x;
    for(int i=0; i<n; i++)  cin >> a[i];
    int cur = 0;
    for(int i=0; i<n; i++) {
        cur += a[i];
        if(cur > x) {
            cout << i+1;
            exit(0);
        }
    }
    cout << n+1;
}


Measured memory_bytes: 3624
import copy
import itertools

def main():
    H, W, K = map(int, input().split())
    # あとで足し算で計算するので#は1にそれ以外は0へ
    C = [[1 if v == '#' else 0 for v in input()] for _ in range(H)]
    ans = 0
    # 選んだところは0に塗り直す
    for x in range(2**H):
        for y in range(2**W):
            cnt = 0
            c = copy.deepcopy(C)
            for h in range(H):
                if(x >> h) & 1:
                    for w in range(W):
                        c[h][w] = 0
            for w in range(W):
                if(y >> w) & 1:
                    for h in range(H):
                        c[h][w] = 0
            # flatten
            cnt = sum(list(itertools.chain.from_iterable(c)))
            if cnt == K:
                ans += 1
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include <stdio.h>
#include <vector>

typedef struct{
  int to;
  int cap;
  int rev;
} edge;

int v;
std::vector<edge> vec[100];
bool flag[100];

int min(int a, int b) {
  return a > b ? b : a;
}

int dfs(int a, int b) {
  int i;
  if(a == v - 1) return b;
  flag[a] = false;
  for(i = 0; i < vec[a].size(); ++i) if(flag[vec[a][i].to] && vec[a][i].cap) {
    edge *e = &vec[a][i];
    int t = min(b, (*e).cap), d;
    d = dfs((*e).to, t);
    if(d) {
      (*e).cap -= d;
      vec[(*e).to][(*e).rev].cap += d;
      //flag[a] = true;
      return d;
    }
  }
  //flag[a] = true;
  return 0;
}

int main(void) {
  int i, j, k, e, a, b, c, ans = 0;
  scanf("%d%d", &v, &e);
  for(i = 0; i < v; ++i) flag[i] = true;
  flag[0] = false;
  for(i = 0; i < e; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    edge ta, tb;
    ta.to = b, ta.cap = c, ta.rev = vec[b].size();
    tb.to = a, tb.cap = 0, tb.rev = vec[a].size();
    vec[a].push_back(ta);
    vec[b].push_back(tb);
  }
  while( 1 ) {
    for(i = 0; i < v; ++i) flag[i] = true;
    flag[0] = false;
    a = dfs(0, 10e8);
    if(a) ans += a;
    else break;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,sum=0;
    cin>>n;
    map<ll,ll>mp;
    for(ll i=0; i<n; i++)
    {
        ll a;
        cin>>a;
        sum+=a;
        mp[a]++;
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        mp[b]+=mp[a];
        sum=sum-(mp[a]*a);
        sum+=mp[a]*b;
        mp[a]=0;
        cout<<sum<<endl;
    }
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var c = Console.ReadLine();
		Console.WriteLine(c.Replace("hi", "").Length == 0 ? "Yes" : "No");
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


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

int main(int argc, const char * argv[]) {
    string n = "";
    cin >> n;
    if(n[0] == n[1] && n[1] == n[2]){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    double r;cin>>r;
    cout<<2*r*3.14159265358979<<endl;
}

Measured memory_bytes: 3804
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
vector<double>a(3005);li n,n1=0,n2=0,n3=0,k;
li AA[100005];
li ff(li i){
    if(i<0) {return(1);}
    if(i==0) return(0);
    if(AA[i]!=-1) return(AA[i]);    
for(li i1=0;i1<n;i1++){if(ff(i-a[i1])==0){AA[i]=1;return(AA[i]);}}
AA[i]=0;return(AA[i]);}
int main(){readl(n);readl(k);memset(AA,-1,sizeof(AA));li i;
for(i=0;i<n;i++) {cin>>a[i];}
li ans=ff(k);
if(ans==1) cout<<"First";
else cout<<"Second";
}


Measured memory_bytes: 3840
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

   
int main(){
int R,G,B,N;
cin >> R >> G >> B >> N;
long long ans =0;
for(int i = 0;i <= N; i++){
	for(int j = 0; j <= N;j++){
		if((N-i*R-j*G)%B==0 && (N-i*R-j*G)>=0){
			ans++;
			
	}
	}
}
cout << ans <<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))
 

int main(){ 
	ll N;
	cin >> N;
	vector<ll> H(N);
	FOR(i,0,N)cin >> H[i];
	bool ok = true;

	H[0]--;
	FOR(i,1,N){
		if(H[i-1]<H[i]){
			H[i]--;
		}
		if(H[i-1]>H[i])ok=false;
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 1024
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func strToInt(str string) []int {
	var ret []int
	for _, s := range strings.Split(str, " ") {
		num, _ := strconv.Atoi(s)
		ret = append(ret, num)
	}
	return ret
}

func main() {
	var n int
	ans := 0
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	vs := strToInt(readLine(sc))
	cs := strToInt(readLine(sc))
	for i := 0; i < n; i++ {
		if vs[i]-cs[i] > 0 {
			ans += (vs[i] - cs[i])
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

#define N 36

struct Card{
  char pattern;
  int value;
};
typedef struct Card card;

void BubbleSort(card *, int);
void SelectionSort(card *, int);
int IsStable(card *, card *, int);
void PrintState(card *, int);

void BubbleSort(card *C1, int n){
  int i,j;
  card tmp;

  for(i=0;i<N;i++){
    for(j=n-1;j>=1;j--){
      if(C1[j].value < C1[j-1].value){
        tmp=C1[j];
        C1[j]=C1[j-1];
        C1[j-1]=tmp;
      }
    }
  }
  return;
}

void SelectionSort(card *C2, int n){
  int i,j,minj;
  card tmp;
  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i;j<n;j++) if(C2[j].value < C2[minj].value) minj=j;
    tmp=C2[i];
    C2[i]=C2[minj];
    C2[minj]=tmp;
  }
  return;
}

int IsStable(card *C1, card *C2, int n){
  int i;
  for(i=0;i<n;i++) if(C1[i].pattern != C2[i].pattern) return 0;
  return 1;
}

void PrintState(card *C, int n){
  int i;
  for(i=0;i<n;i++){
    printf("%c%d",C[i].pattern,C[i].value);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  return;
}

int main(void){
  int n,i,j;
  card C1[N], C2[N],data[N];
  char space;

  //input
  scanf("%d%c",&n,&space);
  for(i=0;i<n;i++){
    scanf("%c%d%c",&data[i].pattern,&data[i].value,&space);
    C1[i]=data[i];
    C2[i]=data[i];
  }

  BubbleSort(C1,n);
  PrintState(C1,n);
  printf("Stable\n");

  SelectionSort(C2,n);
  PrintState(C2,n);
  if(IsStable(C1, C2, n)) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

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

using namespace std;

int selectionSort(int a[], int n) {
    int ans = 0;

    for (int i = 0; i < n - 1; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (a[j] < a[minj])
                minj = j;
        }
        if (i != minj) {
            swap(a[i], a[minj]);
            ans++;
        }
    }

    return ans;
}

int main() {
    int n, ans;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    ans = selectionSort(a, n);
    for (int i = 0; i < n; i++) {
        if (i)
            printf(" %d", a[i]);
        else
            printf("%d", a[i]);
    }
    printf("\n%d\n", ans);
}


Measured memory_bytes: 3224
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
int main(){
    ll a,b,c;cin>>a>>b>>c;
    if(a+b>=c){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define fdto(i, r, l) for(int i = r; i >= l; --i)
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i;
    string str;
    cin>>n;
    ll cnt1=0,cnt2=0,cnt3=0,cnt4=0;
    for(i=0;i<n;i++)
    {
        cin>>str;

        if(str[0]=='A')
        cnt1++;
        else if(str[0]=='W')
        cnt2++;
        else if(str[0]=='T')
        cnt3++;
        else if(str[0]=='R')
        cnt4++;
    }
    cout<<"AC x "<<cnt1<<endl;
    cout<<"WA x "<<cnt2<<endl;
    cout<<"TLE x "<<cnt3<<endl;
    cout<<"RE x "<<cnt4<<endl;

    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}

int main(){
   _;
 int a,b,m;cin>>a>>b>>m;
 vector<int> aa(a),bb(b);
 for(int i=0;i<a;i++)cin>>aa[i];
 for(int i=0;i<b;i++)cin>>bb[i];
 ll ans=*min_element(aa.begin(),aa.end())+*min_element(bb.begin(),bb.end());
 for(int i=0;i<m;i++){
     int x,y,z;cin>>x>>y>>z;
     ans=min(ans,1ll*aa[x-1]+bb[y-1]-z);
 }
cout<<max(0ll,ans);
}

Measured memory_bytes: 1024
N = gets.to_i
A = gets.split.map(&:to_i)

P = 1_000_000_007
Inv = [0, 1]
(2..(N + 1)).each do |i|
  Inv[i] = P - (P / i) * Inv[P % i] % P
end

Fac = (2..(N + 1)).inject([1, 1]) {|ar, i| ar << ar.last * i % P; ar}

FacInv = [1]
(1..(N + 1)).each do |i|
  FacInv[i] = FacInv[i - 1] * Inv[i] % P
end

def nCr(n, r)
  denomi = FacInv[r] * FacInv[n - r] % P
  (Fac[n] * denomi) % P
end

R = Array.new(N)
A.each_with_index do |x, i|
  if R[x]
    J = R[x] + N - i
    break
  else
    R[x] = i
  end
end

puts N
(2..(N + 1)).each do |k|
  if k - 1 > J
    puts nCr(N + 1, k)
  else
    puts (nCr(N + 1, k) - nCr(J, k - 1) + P) % P
  end
end

Measured memory_bytes: 14804