akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using namespace std;

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

    if (s == "SUN")
    {
        cout << "7" << endl;
        return 0;
    }
    if (s == "MON")
    {
        cout << "6" << endl;
        return 0;
    }
    if (s == "TUE")
    {
        cout << "5" << endl;
        return 0;
    }
    if (s == "WED")
    {
        cout << "4" << endl;
        return 0;
    }
    if (s == "THU")
    {
        cout << "3" << endl;
        return 0;
    }
    if (s == "FRI")
    {
        cout << "2" << endl;
        return 0;
    }
    if (s == "SAT")
    {
        cout << "1" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N = int(readline())
graph = [[] for _ in range(N+1)]
AB = []

for _ in range(N-1):
    a, b = map(int, readline().split())
    AB.append((a, b))
    graph[a].append(b)
    graph[b].append(a)

parent = [0] * (N+1)
root = 1
stack = [root]
color = [0] * (N+1)
while stack:
    x = stack.pop()
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == ng:
            c += 1
        parent[y] = x
        color[y] = c
        c += 1
        stack.append(y)

print(max(color))

for a, b in AB:
    if parent[a] == b:
        print(color[a])
    else:
        print(color[b])

Measured memory_bytes: 30896
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	ll R = 0;
	ll G = 0;
	ll ret = 0;

	cin >> R;
	cin >> G;
	ret = 2 * G - R;

	cout << ret << endl;

	return 0;
}





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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cerr << #x << "=" << x << endl

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<bool> bv;

int main(void) {
    
    int a, b, x;
    cin >> a >> b >> x;

    if(a<=x && x<=a+b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    stack<ll> s;
    REP(i, N) {
        if (S[i] == 'R')
            s.push(i);
    }

    ll ans = 0;
    REP(i, N) {
        if (s.empty())
            break;

        if (S[i] == 'R')
            continue;

        ll t = s.top();
        s.pop();
        if (t < i)
            break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for(int i = 0; i < h; i++) cin >> a[i];

    vector<bool> isliveh(h, true);
    vector<bool> islivew(w, true);
    for(int i = 0; i < h; i++){
        bool isexist = false;
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#') isexist = true;
        }
        if(!isexist) isliveh[i] = false;
    }
    for(int i = 0; i < w; i++){
        bool isexist = false;
        for(int j = 0; j < h; j++){
            if(a[j][i] == '#') isexist = true;
        }
        if(!isexist) islivew[i] = false;
    }

    vector<string> ans;
    for(int i = 0; i < h; i++){
        if(!isliveh[i]) continue;
        ans.push_back("");
        for(int j = 0; j < w; j++){
            if(!islivew[j]) continue;
            ans[ans.size()-1] += a[i][j];
        }
    }

    for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void){

long long int a,b;

scanf("%lld %lld",&a,&b);

if (a*b<0 ||a*b==0){
printf("Zero\n");
return 0;
}else if((a<0 && b<0) &&(b-a)%2 == 0){
printf("Negative\n");
return 0;
}
printf("Positive\n");
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b ;
  cin >> a >> b ;
  if ( a ==1){
    a=14;
  }
  if ( b ==1){
    b=14;
  }
  cout << ( a<b ? "Bob" : ( a==b ? "Draw" : "Alice")) << endl;
}
  

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

int n;

bool checkNum(int i) {
  if (i % 3 == 0) {
    cout << " " << i;
    return true;
  }
  return false;
}

void include3(int i, int x) {
  if (x % 10 == 3) {
    cout << " " << i;
  } else {
    x /= 10;
    if (x) include3(i, x);
  }
}

void call() {
  int i = 1;
  do {
    int x = i;
    if (! checkNum(i)) include3(i, x);
  } while (++i <= n);
}

int main() {
  cin >> n;
  call();
  cout << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	vector<int> p(m);
	vector<vector<int> > vals;
	for(int i = 0; i < m; i++){
		int k; cin >> k;
		vector<int> now;
		for(int j = 0; j < k; j++){
			int x; cin >> x; x--;
			now.push_back(x);
		}
		vals.push_back(now);
	}
	for(int i = 0; i < m; i++) cin >> p[i];
	int ans = 0;
	for(int i = 0; i < 1<<n; i++){
		bool ok = true;
		for(int j = 0; j < m; j++){
			int val = 0;
			for(int k : vals[j]) val += (i>>k)&1;
			val %= 2;
			ok &= val == p[j];
		}
		ans += ok;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=acos(-1.0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll dp[62][3];
    memset(dp,0,sizeof dp);
    dp[61][0]=1;
    rrep(i,60,0){
        ll y=1LL<<i;
        ll t=n/y;
        if(t%2==1){
            (dp[i][0]+=dp[i+1][0])%=mod;
            (dp[i][1]+=dp[i+1][0]+dp[i+1][1])%=mod;
            (dp[i][2]+=dp[i+1][1]*2+dp[i+1][2]*3)%=mod;
        }
        else{
            (dp[i][0]+=dp[i+1][0]+dp[i+1][1])%=mod;
            (dp[i][1]+=dp[i+1][1])%=mod;
            (dp[i][2]+=dp[i+1][1]+dp[i+1][2]*3)%=mod;
        }
    }
    ll ans=dp[0][0]+dp[0][1]+dp[0][2];
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}

Measured memory_bytes: 3616
n=int(raw_input())
a=map(int,raw_input().split())

def count(sign):
	_sum=0
	_count=0
	global n,a
	for num in a:
		_sum+=num
		if sign:
			if _sum>0:
				pass
			else:
				_count+=(1-_sum)
				_sum+=(1-_sum)
			sign=False
		else:
			if _sum<0:
				pass
			else:
				_count+=(_sum+1)
				_sum-=(_sum+1)
			sign=True
	return _count
				
		


if n==0:
	print 0
else:
	print min(count(True),count(False))
	
	

Measured memory_bytes: 11248
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N, M;
	cin >> N >> M;
	vector<int>cnt(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		cnt[a]++;
		cnt[b]++;
	}
	for (int i = 0; i < N; i++) {
		if(cnt[i] % 2){
			puts("NO");
			return 0;
		}
	}
	puts("YES");

	return 0;
}

Measured memory_bytes: 640
def main():
    sx, sy, tx, ty = (int(i) for i in input().split())
    dx = tx - sx
    dy = ty - sy
    ans = "U" * dy + "R" * dx
    ans = ans + "D" * dy + "L" * dx
    ans = ans + "L" + "U" * (dy+1) + "R" * (dx+1) + "D"
    ans = ans + "R" + "D" * (dy+1) + "L" * (dx+1) + "U"
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import sys

stdin = sys.stdin

ns = lambda: stdin.readline()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

N = ni()
S = ns().strip()

d = 0
mind = 0

for i in range(len(S)):
    if(S[i] == '('):
        d += 1
    else:
        d -= 1
    mind = min(mind,d)
print ('('*(-mind) + S + ')'*(d-mind))

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const  long long INF = 1LL << 60;
typedef  long long ll;
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 ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
int K,S; cin >> K >> S;
ll cnt = 0;
rep(i,K+1)rep(j,K+1){
    if(S - i - j >=0 && S - i - j <= K){
        cnt++;
    }
}
cout << cnt << endl;
}






Measured memory_bytes: 256
A,B,C,D,E,F=map(int,input().split())

dil=0
ans=(0,0)
for i in range(F//(A*100)+1):
    F_remainA=F-i*A*100
    for j in range(F_remainA//B*100+1):
        F_remainB=F_remainA-j*B*100   
        for k in range(F_remainB//C+1):
            F_remainC=F_remainB-k*C
            for l in range(F_remainC//D+1):
                if i+j!=0 and k+l!=0:
                    if (k*C+l*D)/(i*A*100+j*B*100+k*C+l*D) > dil and (k*C+l*D)/(i*A+j*B)<=E:
                        dil=(k*C+l*D)/(i*A*100+j*B*100+k*C+l*D)
                        ans=(100*(i*A+j*B)+k*C+l*D, k*C+l*D)

if dil==0:
    print(min(A,B)*100, 0)
else:
    print(*ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
using namespace std;
using P=pair<int,int>;
using PP=pair<P,int>;
const int INF=INT_MAX;

/* RMQ：[0,n-1] について、区間ごとの最小値を管理する構造体
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b): [a,b) での最小の要素を取得。O(log(n))
*/
template <typename T>
struct RMQ {
    const T INF = numeric_limits<T>::max();
    int n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    RMQ(int n_) : n(), dat(n_ * 4, INF) { // 葉の数は 2^x の形
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void update(int i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // the minimum element of [a,b)
    T find(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return INF;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};
signed main(){
    int n,q;
    cin>>n>>q;
    priority_queue<pair<int,P>,vector<pair<int,P>>,greater<>> c;
    for(int i=0;i<n;i++){
        int s,t,x;
        cin>>s>>t>>x;
        c.push(make_pair(s-x,P(x,i)));
        c.push(make_pair(t-x,P(x,i)));
    } 
    vector<int> d(q);
    for(int i=0;i<q;i++){
        cin>>d[i];
    }
    RMQ<int> r(n);
    for(int i=0;i<q;i++){
        queue<pair<int,P>> task;
        while(!c.empty()&&c.top().first<=d[i]){
            int p=c.top().second.first,idx=c.top().second.second;
            //cout<<c.top().first<<" "<<p<<" "<<idx<<endl;
            if(r.find(idx,idx+1)==INF){
                r.update(idx,p);
            }else r.update(idx,INF);
            c.pop();
        }
        if(r.find(0,n)==INF)cout<<-1<<endl;
        else cout<<r.find(0,n)<<endl;
    }
}

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

using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;

unordered_map<ll,ll> res;
ll wes,W;
vector<vector<int>> val(5);
unordered_set<ll> mys;

ll trc(ll cur, ll i1,ll i2,ll i3,ll i4){
    if(!mys.insert(i1+i2*1000+i3*1000000+i4*1000000000).second)
        return res[cur];
    ll rs = res[cur];
    if(i1<val[0].size()&& (cur+wes)<=W){
        
        res[cur+wes] =res[cur]+val[0][val[0].size()-i1-1];
        rs = max(rs,trc(cur+wes,i1+1,i2,i3,i4));
        
    }
    if(i2<val[1].size()&& (cur+wes+1)<=W){
       
        res[cur+wes+1] = res[cur]+val[1][val[1].size()-i2-1];
        rs = max(rs,trc(cur+wes+1,i1,i2+1,i3,i4));
       
    }
    if(i3<val[2].size()&& (cur+wes+2)<=W){
        
        res[cur+wes+2] = res[cur]+val[2][val[2].size()-i3-1];
        rs = max(rs,trc(cur+wes+2,i1,i2,i3+1,i4));
        
    } 
    if(i4<val[3].size()&& (cur+wes+3)<=W){
        
        res[cur+wes+3] = res[cur]+val[3][val[3].size()-i4-1];
        rs = max(rs,trc(cur+wes+3,i1,i2,i3,i4+1));
        
    }
    return rs;
}

int main(){
    //ios_base::sync_with_stdio(0);
    ll N;
    cin>>N>>W;
    ll a,b;
    cin>>wes>>b;
    val[0].pb(b);
    //cout<<wes<<" "<<b<<endl;
    for(int i = 2;i<=N;i++){
        cin>>a>>b;
        //cout<<a<<" "<<b<<endl;
        val[a-wes].pb(b);
    }
    for(int i = 0;i<4;i++){
        sort(val[i].begin(),val[i].end());
    }
    
    ll x = 0;
    x = max(x, trc(0,0,0,0,0));
    
    cout<<x;
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 7752
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;



ll N, M;

int main() {
	cin >> N >> M;
	vector<ll> sum(N+1,0);
	map<ll, ll>mp;

	rep(i, 1, N+1) {
		cin >> sum[i];
	}
	rep(i, 1, N+1) {
		sum[i] += sum[i - 1];
	}
	rep(i, 0, N + 1) {
		sum[i] %= M;
	}
	rep(i, 0, N + 1) {
		mp[sum[i]]++;
	}

	ll ans = 0;
	for (auto x : mp) {
		if (x.second >= 2) {
			ans += ((x.second)*(x.second - 1) / 2);
		}
	}

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define xmod int(1e9)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pi 3.14159265358
#define inf long long(1e18)
using namespace std;

int n,a[200005],mxp,mx,sxp,smx;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i] >= mx){
			smx=mx; mx=a[i];
			sxp=mxp; mxp=i;
		}
		else
		if (a[i] > smx){
			smx=a[i]; sxp=i;
		}
	}
	for (int i=1;i<=n;i++){
		if (i != mxp)
		printf("%d\n",mx);
		else
		printf("%d\n",smx);
	}
	return 0;
}
//4 11

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n, a[200020];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int idx = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == idx) idx++;
    }

    if (idx == 1) cout << -1 << endl;
    else cout << n - idx + 1 << endl;
}

Measured memory_bytes: 1024
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B 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 (LLONG_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_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;
    int K = S.size();

    int win = 0;
    REP(i,K) {
        if (S[i] == 'o') win++;
    }

    win += 15 - K;

    string ans = win >= 8 ? "YES" : "NO";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long dat[100010];
long long vec[100010][2];
int main()
{
    int num,query,i,j,z,zb;
    long long t,tt,za;
    i=0;
    scanf("%d%lld%d",&num,&t,&query);
    vec[0][0]=-3000000000000000000LL;
    vec[0][1]=1;
    for(;i<num;i++){
        scanf("%lld%d",&za,&zb);
        vec[i+1][0]=za;
        vec[i+1][1]=zb;
    }
    vec[num+1][0]=3000000000000000000LL;
    vec[num+1][1]=2;
    i=0;
    for(;i<=num;i++){
        if(vec[i][1]==1&&vec[i+1][1]==2){
            tt=(vec[i][0]+vec[i+1][0])/2;
            j=i;
            for(;j>=0;j--){
                if(vec[j][1]==1)dat[j]=tt;
                else break;
            }
            j=i+1;
            for(;j<num+2;j++){
                if(vec[j][1]==2)dat[j]=tt;
                else break;
            }
        }
    }
    i=0;
    for(;i<query;i++){
        scanf("%d",&z);
        if(vec[z][1]==1){
            printf("%lld\n",(vec[z][0]+t<dat[z])?(vec[z][0]+t):(dat[z]));
        }else{
            printf("%lld\n",(vec[z][0]-t<dat[z])?(dat[z]):(vec[z][0]-t));
        }
    }
    return 0;
}

Measured memory_bytes: 5036
N,M = map(int, input().split())
LR = [[int(x) for x in input().split()] for _ in range(M)]
L = []
R = []
for i in range(M):
    L.append(LR[i][0])
    R.append(LR[i][1])
maxL = max(L)
minR = min(R)
if minR - maxL < 0:
    print(0)
else:
    print(minR-maxL+1)

Measured memory_bytes: 22852
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const  long long INF = 1LL << 60;
typedef  long long ll;
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 ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
int N; cin >> N;
set<int> s; 
bool ok = true;
rep(i,N){
    int a; cin >> a;
    if(s.count(a)){
        ok = false;
    }
    else{
        s.insert(a);
    }
}
if(ok) cout << "YES" << endl;
else cout << "NO" << endl;
}






Measured memory_bytes: 10496
n=int(input())
R=[]
for _ in range(n):
  x,l=map(int,input().split())
  R.append([x-l,x+l])

R=sorted(R,key=lambda x:x[1])
ans=n
for i in range(1,n):
  if R[i][0]<R[i-1][1]:
    ans-=1
    R[i][1]=R[i-1][1]
  
print(ans)

Measured memory_bytes: 92992
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200_000)

def solve(N: int, a: "List[int]", b: "List[int]"):
    from itertools import count
    edges = [[] for _ in range(N)]
    for i, (aa, bb) in enumerate(zip(a, b)):
        edges[aa-1].append((bb-1, i))
        edges[bb-1].append((aa-1, i))
    ans = [None] * (N-1)
    visited = set()
    def dfs(n, c):
        if n in visited:
            return
        visited.add(n)
        for (nn, i), cc in zip(filter(lambda x: x[0] not in visited, edges[n]),
                          filter(lambda y: y != c, count(1))):
            ans[i] = cc
            dfs(nn, cc)
    dfs(0, None)
    return [max(ans)] + ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    print(*solve(N, a, b), sep="\n")

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 147664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define dloop(i,a,b) for(ll i=a;i>=b;--i)
#define all(a) a.begin(),a.end()
#define lar 1000000007
#define pq priority_queue
#define pll pair<ll,ll>
#define ss second
#define ff first
#define pb push_back
#define ppb pop_back
#define umap unordered_map
#define ub upper_bound
#define lb lower_bound
#define br "\n"
#define sp " "

void solve(){
   ll s;
   cin>>s;
   ll dp[s+1]={0};
   loop(i,3,s+1)
   {
       loop(j,3,i)
       {
           if(dp[j]&&dp[i-j])
           {
               dp[i] = (dp[i]+dp[i-j])%lar;
           }
       }
       dp[i] = (dp[i]+1)%lar;
   }
   cout<<dp[s]<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}



Measured memory_bytes: 3600
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


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

const int  N = (int) 1e5 + 5;

int n;
int rk[N];

int main() {
	//freopen("test.inp", "r", stdin);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		rk[a] = i;
	}
	for (int i = 1; i <= n; i++) cout << rk[i] << " ";

	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

//------------------------------------------------------------------------------------------------------------------------------

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int main(void) {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> cnt(N + 1);
    for(int i = 0; i < N - 1; i++) {
        cnt[i + 1] = cnt[i];
        if (S[i] == 'A' && S[i + 1] == 'C') cnt[i + 1]++;
    }
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--;r--;
        if (l == 0) cout << cnt[r] << endl;
        else if (S[l - 1] == 'A' && S[l] == 'C') cout << cnt[r] - cnt[l - 1] - 1 << endl;
        else cout << cnt[r] - cnt[l - 1] << endl;
    }
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int  main()
{
  int N;
  vector<int> height;
  vector<int> dp(N);
  
  cin >> N;
  int x;
  for(int i=0;i<N;i++)
  {
    cin >> x;
  	height.push_back(x);
	}
  
  dp[0]=0;
  dp[1]=abs(height[0]-height[1]);
  for(int i=2;i<N;i++)
    dp[i]=min(dp[i-1]+abs(height[i-1]-height[i]),dp[i-2]+abs(height[i-2]-height[i]));

  cout << dp[N-1];
  
}

Measured memory_bytes: 17276
import sys
input = lambda: sys.stdin.readline().rstrip()

from collections import deque
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

Y = [(-10**9, 10**9) for _ in range(N)]
K = int(input())
for _ in range(K):
    v, p = map(int, input().split())
    Y[v-1] = (p, p)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)


def calc():
    for i in R[::-1]:
        e, o = 0, 0
        l, r = Y[i]
        if r != 10 ** 9:
            if l % 2:
                o = 1
            else:
                e = 1
        for j in X[i]:
            a, b = Y[j]
            if b == 10**9: continue
            if a % 2:
                e = 1
            else:
                o = 1
            l = max(l, a - 1)
            r = min(r, b + 1)
        if (e and o) or (l > r):
            print("No")
            return 0
        elif e or o:
            Y[i] = (l, r)
    
    for i in R[1:]:
        if Y[P[i]][0] - 1 >= Y[i][0]:
            Y[i] = (Y[P[i]][0] - 1, 0)
        else:
            Y[i] = (Y[P[i]][0] + 1, 0)
    
    print("Yes")
    for i in range(N):
        print(Y[i][0])

calc()

Measured memory_bytes: 80176
#include <bits/stdc++.h>
using namespace std;
string s;
long n;
int main()
{
    cin >> s;
    n=s.length();
    s=" "+s;
    for (long i=1;i<=n;i++){
        if (s[i]==s[i+2]) {
            cout << i << " " << i+2;
            return 0;
        }
        if (s[i]==s[i+1]) {
            cout <<i << " " << i+1;
            return 0;
        }
    }
    cout << -1 << " " << -1;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int dp[101][2][4];
//dp[i][j][k]...i桁まで見てj = 0...同じ..1..異なる k...0じゃない数

int main(void) {
    string n;
    cin >> n;
    int K;
    cin >> K;

    int sz = n.size();

    dp[0][0][0] = 1;


    //例えばi = 0ならば、i = 1に持っていける数は大体10個くらい。
    //このときdp[0][0][0](値は1)を合計10回dp[1][0][1]とかdp[1][1][1]とかに持っていきたいから、
    //        下記のようなfor文の使い方になる。
    //配る前の状態をforで全列挙して、最後のforのなかで遷移先を決定するという、いわゆる「配るDP」。


    for (int i = 0; i < sz; i++) {

        int x = n[i] - '0';
        for (int j = 0; j < 2; j++) for (int k = 0; k < 4; k++) for (int d = 0; d < 10; d++) {
            int ni = i + 1;
            int nj = j;
            int nk = k;

            if (d != 0) nk++;
            if (nk > K) continue;

            if (j == 0) {
                if (d < x) nj = 1;
                if (d > x) continue;
            }
        


            dp[ni][nj][nk] += dp[i][j][k];
            
        }
        
    }
    
    cout << dp[sz][0][K] + dp[sz][1][K] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = {i: int(input()) for i in range(1, N + 1)}
result = 0
i = 1
while True:
    if not i in a:
        result = -1
        break
    result += 1
    nexti = a[i]
    if nexti == 2:
        break
    del a[i]
    i = nexti
print(result)

Measured memory_bytes: 17892
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N,W,sn;
map<int,vector<int>> w;

ll dfs(int d,ll nw,ll nv)
{
	ll rw=nw,rv=nv,r=0;
	if(d==4)
	{
		if(nw<=W)
			r=nv;
	}
	else
	{
		r=dfs(d+1,rw,rv);
		for(int i=0;i<w[sn+d].size();i++)
		{
			rw+=sn+d;rv+=w[sn+d][i];
			ll t=dfs(d+1,rw,rv);
			r=max(t,r);
		}
	}
	return r;
}

int main()
{
	scanf("%d%d",&N,&W);
	for(int i=0;i<N;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(i==0)
		{
			sn=a;
			for(int i=0;i<4;i++)w[sn+i].resize(0);
		}
		w[a].push_back(b);
		sort(w[a].begin(),w[a].end(),greater<int>());
	}
	cout<<dfs(0,0,0)<<endl;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
l = [lis[i]-li[i] for i in range(n)]
l.sort()
if sum(l) < 0:
  print(-1)
  exit()
husai = 0
ans = 0
for num in l:
  if num < 0:
    ans += 1
    husai -= num
an = 0
kasan = 0
while kasan < husai:
  an += 1
  kasan += l[-an]
ans += an
print(ans)

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

int main(){
    vector <int> ds(5);
    //vector <int> rs(5);
    int rmin=9;
    int last=0;
    rep(i,5) {
        cin>>ds[i];
        if (rmin<=(ds[i]-1)%10) {
        } else {
            rmin=(ds[i]-1)%10;
            last=ds[i];
        }
    //cout<<last<<endl;
        
    }
    int sm=0;
    rep(i,5) {
        sm +=((ds[i]+9)/10)*10;
    }
    sm-=((last+9)/10)*10;
    sm+=last;
    cout<<sm<<endl;
    
   
}

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

YES = "YES"  # type: str
NO = "NO"  # type: str

# dream dreamer erase eraser
def solve(S: str):
    hoge = S.replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
    print(NO if hoge else YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
int main(){
  int i,j;
  int n[10];
  char s[11];
  while(scanf("%s",s)!=-1){
    for(i=0;i<10;i++)
      n[i]=s[i]-'0';
    for(i=9;i>0;i--)
      for(j=0;j<i;j++)
	n[j]=(n[j]+n[j+1])%10;
    printf("%d\n",n[0]);
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
 
public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int x = stdIn.nextInt();

        if(x >= 30){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35624
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define nl '\n'
#define si(i) scanf("%d", &i)
typedef long long ll;
int n;
long long k, a[100005], number_of_ones[45];
long long ans, sum;

int main() {

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

    for ( int i = 0; i <= 40; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            if ( a[j] & ((ll)1<<i) ) number_of_ones[i]++;
        }
    }

    for ( int i = 40; i >= 0; i-- ) {
        if ( (k & ((ll)1<<i)) == 0 ) {
            sum += ((ll)1<<i) * number_of_ones[i];
        }
        else {
            long long x = sum;
            x += ((ll)1<<i) * number_of_ones[i];
            for ( int j = i - 1; j >= 0; j-- ) {
                x += ((ll) 1<<j) * max( number_of_ones[j], n - number_of_ones[j]);
                ans = max( ans, x);
            }
            sum += ((ll)1<<i) * ( n - number_of_ones[i] );
        }
    }
    ans = max( ans, sum);
    cout << ans << nl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
pair<int, int> T[200010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> T[i].second >> T[i].first;
	}

	sort(T, T + N);

	int t = 0;
	rep(i, 0, N)
	{
		t += T[i].second;
		if (T[i].first < t)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

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

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

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int main() {
    int m, n;
    cin >> m >> n;
    vector<int> S(m+1), T(m+1);
    for (int i = 0; i < m; ++i) {
        scanf("%d %d", &S[i+1], &T[i+1]);
        S[i+1] += S[i]; T[i+1] += T[i];
    }
    vector<int> A(n), B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
    }
    vector<int> dp(1 << n);
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if(i & (1 << j)) continue;
            chmax(dp[i^(1 << j)], dp[i]);
            int ok = dp[i^(1 << j)], ng = m+1;
            while(ng-ok > 1){
                int mid = (ok+ng)/2;
                if(S[mid]-S[dp[i]] <= A[j] && T[mid]-T[dp[i]] <= B[j]) ok = mid;
                else ng = mid;
            }
            dp[i^(1 << j)] = ok;
        }
    }
    cout << dp.back() << "\n";
    return 0;
}


Measured memory_bytes: 4280
#include<bits/stdc++.h>
using namespace std;
long long n, m, ans;
bool a, b, c, d;

int main(){
    scanf("%lld%lld", &n, &m); n--;
    a = n&1; b = m&1;
    if((n%4 == 1 || n%4 == 2 ) ^ (m%4 == 1 || m%4 == 2)) ans = 1;
    for(int i = 1; m>>i; i++){
        c = n >> i & 1 ? !a : false; d = m >> i & 1 ? !b : false;
        if(c^d) ans += 1ll << i;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int[] a = new int[10];
        for (int i = 0; i < 10; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(a);
        for (int i = 9; i >= 7; i--)
        {
            Console.WriteLine(a[i]);
        }
    }
}

Measured memory_bytes: 9244
using System;
using System.IO;
namespace Rectangle{
	 class class1{
		 static void Main(){
			string[] str = Console.ReadLine().Split(' ');
			int a=int.Parse(str[0]),b=int.Parse(str[1]);
			Console.Write("{0} {1}\n",area(a,b),length(a,b));
		}

		 static int area(int x,int y){return x*y;}
		
		 static int length(int x,int y){return 2*(x+y);}
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

ll n, a[200010], s[200010], ans;
map<ll, ll>mp;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}
	for (int i = 0;i <= n;i++) {
		ans += mp[s[i]];
		mp[s[i]]++;
	}
	cout << ans << endl;
	return 0;
}


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


int counter(int x){
    
    int tmp=x;
    int result=0;
    while(tmp!=0){
        if(tmp&1) result++;
        tmp=(tmp>>1);
    }
    return result;

    //if(x==0) return 0;
    //return counter(x>>1)+(x&1);

}

int main(){
    int n;
    cin>>n;
    int a[n];
    int x[n][n],y[n][n];

    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }

    int ans=0;

    for(int bits=1;bits<(1<<n);bits++){
        bool ok=true;
        for(int i=0;i<n;i++){
            if(!(bits&(1<<i))) continue;
            for(int j=0;j<a[i];j++){
                if(((bits>>(x[i][j]-1))&1)^y[i][j]) ok=false;
            }
        }
        if(ok) ans=max(ans,counter(bits));
    }
    cout<<ans<<endl;
    return 0;
}

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

int	main()
{
  int			n;
  int			i = -1;
  int			counter = 0;
  int			odd_flag = 0;
  
  cin >> n;
  vector<int>	vec(n);

  while (++i < n)
    cin >> vec.at(i); 
  while (1)
  {
    i = 0;
    while (i < n)
    {
      if (vec.at(i) % 2 == 0)
        vec.at(i) /= 2;
      else
      {
        odd_flag = 1;
        break ;
      }
      i++;
    }
    if (odd_flag == 1)
      break ;
    counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 3544
use std::cmp;
use std::collections::*;
use std::io::{self, Read};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let h: usize = sc.read().unwrap();
    let w: usize = sc.read().unwrap();
    let mut b = sc.read_board(h).unwrap();

    let mut q = VecDeque::new();

    for y in (0..h) {
        for x in (0..w) {
            if b[y][x] == '#' {
                q.push_back((x, y, 0));
            }
        }
    }

    let mut r = 0;
    while let Some((sx, sy, n)) = q.pop_front() {
        for &(dx, dy) in [(0, -1), (-1, 0), (1, 0), (0, 1)].iter() {
            let x = sx as i64 + dx;
            let y = sy as i64 + dy;

            if x < 0 || y < 0 || x >= w as _ || y >= h as _ {
                continue;
            }

            if b[y as usize][x as usize] == '#' {
                continue;
            }

            b[y as usize][x as usize] = '#';
            q.push_back((x as usize, y as usize, n + 1));

            r = n + 1;
        }
    }

    println!("{}", r);
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


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

#define REP(i,n) for(int i=0;i<n;i++)



int main(void){
	int n,l;
	string s;
	cin >> n >> l;
	vector<string> cv;

	REP(i,n) {
		cin >> s;
		cv.push_back(s);
		
	}
	sort(cv.begin(), cv.end());
	
	REP(i,n) {
		cout << cv[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
// 2020-08-28 23:36:44
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n;
  ll c;
  cin >> n >> c;
  vector<ll> x(n), v(n);
  rep(i, n) cin >> x[i] >> v[i];
  vector<ll> vl(n), vr(n), ml(n), mr(n);
  ll ans = 0;
  rep(i, n) {
    int j = n - i - 1;
    vl[i] = v[i] + (i > 0 ? vl[i - 1] : 0);
    vr[j] = v[j] + (i > 0 ? vr[j + 1] : 0);
    ml[i] = max(vl[i] - x[i], (i > 0 ? ml[i - 1] : 0));
    mr[j] = max(vr[j] - (c - x[j]), (i > 0 ? mr[j + 1] : 0));
    chmax(ans, ml[i]);
    chmax(ans, mr[j]);
  }
  rep(i, n - 1) {
    int j = i + 1;
    chmax(ans, vl[i] - x[i] * 2 + mr[j]);
    chmax(ans, ml[i] + vr[j] - (c - x[j]) * 2);
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int o = 0;
    for (int i = 0; i < n - 1; ++i)
        if ((a[i] - a[i + 1]) % 2 == 1)
            o ^= (i + 1);
    if (a[n - 1] % 2 == 1)
        o ^= n;
    if (o != 0)
        cout << "first";
    else
        cout << "second";
    return 0;
}


Measured memory_bytes: 640