akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]){
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long l = c*d/__gcd(c, d);
    long cnt = b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d-b/(l)+(a-1)/l);
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
 
fn abc(mut a: Vec<i32>) -> i32 {
    a.sort_by(|x, y| y.cmp(x));
    let alice: i32 = a.iter().enumerate().filter(|&(i, _)| i%2 == 0).map(|(_, &x)| x).sum();
    let bob: i32 = a.iter().enumerate().filter(|&(i, _)| i%2 != 0).map(|(_, &x)| x).sum();
    return &alice - &bob
}
 
fn main() {
    /*
    assert_eq!(abc(3, 1), 2);
    assert_eq!(abc(2, 7, 4), 5);
    assert_eq!(abc(20, 18, 2, 18), 18);
    */
    let n: i32 = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();
 
    let result = abc(a);
 
    println!("{}", result);
}
 
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;


int main(){
	ll n;
	cin>>n;
	cout<<3*n*n;
}


Measured memory_bytes: 256
#横にn個入力
a, b = map(int, input().split())
count = 0
for i in range(1,a + 1):
    if i < a:
        for j in range(1,31):
            if i == j:
                count += 1
    if i == a:
        for j in range(1,b + 1):
            if i == j:
                count += 1

print(count)

Measured memory_bytes: 3060
#C

n, m = map(int, input().split())
x = list(map(int, input().split()))

x.sort()
length = []
if n >= m:
    print(0)
else:
    #長い道ををm-n個取っておく
    for i in range(m - 1):
        length.append(x[i + 1] - x[i])
    length.sort()
    tmp = sum(length[(m - n):])
    print(x[m-1]-x[0] - tmp)
    # print(x[m-1],length)


Measured memory_bytes: 20512
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    while(true){
        vector<int> te(3);
        vector<int> per(5);
        for(int i=0;i<5;i++){
            int x;
            cin >> x;
            x--;
            if(x == -1) return 0;
            te[x]++;
            per[i] = x;

        }
        if(*min_element(all(te)) > 0 or *max_element(all(te)) == 5){
            for(int i=0;i<5;i++){
                cout << 3 << endl;
            }
        }else{
            vector<char> win(5,false);
            if(te[0] > 0 and te[1] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 0) win[i] = true;
                }
            }
            else if(te[1] > 0 and te[2] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 1) win[i] = true;
                }
            }
            else if(te[2] > 0 and te[0] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 2) win[i] = true;
                }
            }
            for(int i=0;i<5;i++){
                if(win[i]){
                    cout << 1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }
        }
    }
    return 0;
}

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

int main(){
   int N;
   cin>>N;
   int A[N];
    rep(i,N){
        cin>>A[i];
    }

    int64_t max=-1000000000;
    rep(i,N){
        rep(j,N){
            if(A[i]-A[j]>=max){
                max=A[i]-A[j];
            }
        }
    }

    cout<< max <<endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
#include "math.h"
#include <string>
using namespace std;
int h[200005] = { 0 };
int main()
{
	int n, k;
	cin >> n >> k;
	int a;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		h[a]++;
	}
	priority_queue<int>p;
	for (int i = 1; i <= n; i++) {
	p.push(h[i]);
	}
	for (int i = 1; i <= k; i++) {
		a=p.top();
		n -= a;
		p.pop();
	}
	cout << n << endl;
}

Measured memory_bytes: 2168
N,K=map(int, raw_input().split())

ans=0
for b in range(1,N+1):
	p=N/b
	r=N%b
	ans+=p*max(b-K,0)
	if K==0: ans+=max(r-K,0)
	else: ans+=max(r-K+1,0)

print ans

Measured memory_bytes: 5764
#include <iostream>

using namespace std;

int main()
{
    int m=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()/2;i++)
    {
        if(s[i]!=s[s.size()-i-1])
            m++;
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, (input().split())))

done = [0]*N
now = 0
cnt = 1
while True:
    if done[now] != 0:
        start = done[now] - 1
        cycle = cnt - start - 1
        break
    else:
        done[now] = cnt
        now = A[now]-1
        cnt += 1
if K>=start:
    K -= start
    K %= cycle
else:
    now = 0
for _ in range(K):
    now = A[now]-1
print(now+1)

Measured memory_bytes: 32372
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 5001, oo = 1000000000000000000ll;
int n;
int l[maxn], r[maxn];
int dp[2][maxn][2];

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	F1 (i, n) cin >> l[i] >> r[i];
}

void solve()
{
	vector<pii> v;
	F1 (i, n) v.pb(mp(l[i] + r[i], i));
	sort(all(v));
	reverse(all(v));
	F (i, 2) F (j, maxn) dp[i][j][0] = dp[i][j][1] = oo;
	dp[0][0][0] = 0;
	for (int i = 0; i <= n; ++i)
	{
		int p = i & 1;
		int q = p ^ 1;
		if (i != 0)
			F (j, maxn) dp[p][j][0] = dp[p][j][1] = oo;
		for (int x = 0; x <= i; ++x)
		{
			if (x > 0)
			{
				dp[p][x][0] = min(dp[p][x][0], r[v[i - 1].se] + dp[q][x - 1][0] + v[i - 1].fi * (x - 1));
				if (i != n) dp[p][x][1] = min(dp[p][x][1], r[v[i].se] + dp[q][x - 1][1] + v[i].fi * (x - 1));
			}
			if (x != i)
			{
				dp[p][x][0] = min(dp[p][x][0], l[v[i - 1].se] + dp[q][x][0] + v[i - 1].fi * (i - x - 1));
				if (i != n) dp[p][x][1] = min(dp[p][x][1], l[v[i].se] + dp[q][x][1] + v[i].fi * (i - x - 1));
			}
			if (i != n) dp[p][x][1] = min(dp[p][x][1], dp[p][x][0] + n / 2 * v[i].fi);
		}
	}
	int ans = oo;
	int p = n & 1;
	int q = p ^ 1;
	for (int i = 0; i <= n; ++i)
		ans = min(ans, dp[p][i][0]);
	if (n & 1)
		ans = min(ans, dp[q][n / 2][1]);
	cout << ans << '\n';
}

main()
{
	input();
	solve();
}


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

MOD = 2  # type: int

def solve(N: int, a: "List[int]"):
    a = [0] + a
    result = [0 for i in range(N+1)]
    for i in range(N, 0, -1):
        count_baisu = 1

        sum_ = 0
        while count_baisu * i <= N:
            sum_ += result[count_baisu * i]
            count_baisu += 1

        if a[i] == 0:
            if sum_ % 2 == 0:
                result[i] = 0
            else:
                result[i] = 1
        else:
            if sum_ % 2 == 0:
                result[i] = 1
            else:
                result[i] = 0
                
    print(sum(result))

    if sum(result) > 0:
        output = ''
        for i in range(1, N+1):
            if result[i] == 1:
                output += ' %d' % (i)
        print(output[1:])
    
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int N, W;
vector<vector<int>> dp;
int main() {
    cin >> N >> W;
    vector<int> v(N);
    vector<int> w(N);
    REP(i,N){
        cin >> v[i] >> w[i];
    }
    dp.assign(N+1, vector<int>(W+1,0));
    FOR(i,0,N){
        FOR(j,0,W+1){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

            if(j-w[i] >= 0){
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}



Measured memory_bytes: 6760
s = input()
flag = True
if len(s) != 6:
    flag = False

for i in s:
    if ord(i) < 97 or ord(i) > 122:
        flag = False
if len(s) == 6:
    if s[2] != s[3]:
        flag = False
    if s[4] != s[5]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
#define ll long long;
#define MAX 200005;
int main(){
    int n; cin >> n;
    double a[n];
    double res = 0;
    for(int i=0;i<n;i++){
      cin >> a[i];
      double b = (1/a[i]);
      res += b;
      }
      double ans = 1/res;
  cout << setprecision(10)<< ans;
     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main(){
int a,b;
cin >> a >> b;
if(b%a==0){
    cout << b+a;
}else cout << b-a;


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	string s, t;
	cin >> s >> t;
	int l = s.size() - t.size() + 1;
	vector<int>count(l, 0);

	for (int i = 0; i < l; i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] == t[j]) {
				count.at(i) += 1;
			}
		}
	}
	sort(count.begin(), count.end());
	reverse(count.begin(), count.end());
	cout << t.size() - count[0] << endl;


	return 0;
}


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

using namespace std;
typedef long long lint;

void resolve()
{
    lint N, A, B;
    cin >> N >> A >> B;

    lint ans = N / (A + B) * A + min(N % (A + B), A);
    cout << ans << endl;
}

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


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

int main(){
    ll N; cin >> N;
    vector<int> v;
    ll last_val = 0;
    for (int i = 2; i <= sqrt(N); i++)
    {
        if(N%i==0){
            v.push_back(1);
            N/=i;
            while(N%i==0) {
                v[v.size()-1]++;
                N/=i;
            }
            last_val = i;
        }
    }
    if(N!=1) v.push_back(1);

    ll ans = 0;
    for(int i : v){
        ans += (sqrt(8*i+1) - 1) / 2;
    }
    cout << ans << endl;
}


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

int main(){
  long long N,sum,ans,ans2;
  cin>>N;
  sum=0;
  ans=0;
  ans2=0;
  vector<long long>x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  for(int i=0;i<N;i++){
    sum+=x[i];
    if(i%2==0&&sum<=0){
       ans+=1-sum;
      sum=1;
    }
    if(i%2==1&&sum>=0){
      ans+=1+sum;
      sum=-1;
    }
    ans2=ans;
  }
  ans=0;
  sum=0;
    for(int i=0;i<N;i++){
    sum+=x[i];
    if(i%2==1&&sum<=0){
       ans+=1-sum;
      sum=1;
    }
    if(i%2==0&&sum>=0){
      ans+=1+sum;
      sum=-1;
    }
  }
 
      cout<<min(ans,ans2)<<endl;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REP_REV(i,a,b) for (int i = a; i >= b; i--)
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;

void solve() {
	float n, x, t;
	cin >> n >> x >> t;
	int ans = ceil(n / x) * t;
	cout << ans;
	/*
	int n;
	cin >> n;
	int highest = 7;
	int noHighest = 3;
	int bessie = 7, elsie = 7, mildred = 7;
	int ans = 0;
	bool bessieOn = true, elsieOn = true, mildredOn = true;
	vector<tuple<int, string, int>> records;
	REP(i, 0, n - 1) {
		int day, change;
		string name;
		cin >> day >> name >> change;
		tuple<int, string, int> record = tie(day, name, change);
		records.push_back(record);
	}
	sort(records.begin(), records.end());
	REP(i, 0, n - 1) {
		int currNoHighest = 0;
		int high = highest;
		if (get<1>(records[i]) == "Bessie") bessie += get<2>(records[i]);
		if (get<1>(records[i]) == "Mildred") mildred += get<2>(records[i]);
		if (get<1>(records[i]) == "Elsie") elsie += get<2>(records[i]);
		highest = max(bessie, max(elsie, mildred));

		bool bessieOnNext = bessie == highest;
		bool elsieOnNext = elsie == highest;
		bool mildredOnNext = mildred == highest;
		if (bessieOn != bessieOnNext || elsieOn != elsieOnNext || mildredOn != mildredOnNext) {
			ans++;
		}
		bessieOn = bessieOnNext;
		elsieOn = elsieOnNext;
		mildredOn = mildredOnNext;
	}

	cout << ans;*/
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("measurement.in", "r", stdin);
	//freopen("measurement.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//ll t;
	//cin >> t;
	//while (t--) {
	solve();
	//}
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m), c(m);
    REP(i, n) cin >> a[i];
    REP(i, m) cin >> b[i] >> c[i];

    vector<P> p;
    REP(i, m)
    {
        p.pb(make_pair(c[i], b[i]));
    }

    sort(all(a));
    sort(all(p), greater<P>());
    
    vector<int> d(n);
    for(int i = 0, j = 0; i < m && j < n; i++)
    {
        while(p[i].second > 0 && j < n)
        {
            d[j] = p[i].first;
            j++;
            p[i].second--;
        }
    }
    priority_queue<LL> que;
    REP(i, n) que.push(a[i]);
    REP(i, n) que.push(d[i]);

    LL ans = 0;
    REP(i, n)
    {
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 8048
S = input()
cnt = [0, 0, 0]
for s in S:
    if s == "a":
        cnt[0] += 1
    elif s == "b":
        cnt[1] += 1
    else:
        cnt[2] += 1
base = len(S) // 3
ans = False
for i in range(3):
    if base <= cnt[i] <= base+1:
        pass
    else:
        break
else:
    ans = True
if ans:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
long X,Y,Z,K,i,j,k;
main(){
  cin>>X>>Y>>Z>>K;
  vector<long> A(X),B(Y),C(Z),ABC;
  for(i=0;i<X;i++)cin>>A[i];for(i=0;i<Y;i++)cin>>B[i];for(i=0;i<Z;i++)cin>>C[i];
  sort(A.rbegin(),A.rend());sort(B.rbegin(),B.rend());sort(C.rbegin(),C.rend());
  for(i=0;i<X;i++)for(j=0;j<Y;j++)for(k=0;k<Z;k++){if((i+1)*(j+1)*(k+1)>K)break;ABC.push_back(A[i]+B[j]+C[k]);}
  sort(ABC.rbegin(),ABC.rend());
  for(i=0;i<K;i++)cout<<ABC[i]<<endl;
}


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

const int MAXN = 100;
const int MAXK = 100005;

int K;			//Initial SUM
int N;			//Number of elements in sack
int a[MAXN];	//Set
int dp[MAXK];	//dp table

int solve(int k){
	if(dp[k]!=-1)
		return dp[k];

	int winner = 2;	//initially set winner to second

	for(int i=0;i<N;i++)
		if(a[i]<=k){
			if( 2==solve(k-a[i]) ){
				winner = 1;
				break;
			}
		}

	return dp[k] = winner;
}

int main(){
	memset(dp,-1,sizeof(dp));
	
	cin>>N>>K;
	for(int i=0;i<N;i++)
		cin>>a[i];

	cout<< ((solve(K)==1)?"First":"Second") <<endl;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
    #define sz(a) (int)(a).size()
     
    using namespace std;
     
    template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
    template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
    const int INF = 2e5+2;
    const long long hell = 998244353ll;
    
    double dis(vector<int>a,vector<int> b){
    	double ans=0;
    	for(int i=0; i<sz(a); i++){
    		ans += (a[i]-b[i])*(a[i]-b[i]);
    	}
    	return sqrt(ans);
    }

    void solve(){
    	string s;
    	cin>>s;
    	sort(s.begin(), s.end());
    	if(s[0]==s[1]&&s[2]==s[3]&&s[2]!=s[1]){
    		cout<<"Yes"<<endl;
    	}else{
    		cout<<"No"<<endl;
    	}

    }

    int main(){
    	
    	ios_base::sync_with_stdio(0);cin.tie(0);
    	
    	int q=1;
    #ifdef LOCAL
      	cin>>q;
#endif
	while(q--){
	 solve();
	}

    #ifdef LOCAL
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif	
    	return 0;
    }

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc160/tasks/abc160_e

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int A_MAX = 1e5;
const int B_MAX = 1e5;
const int C_MAX = 1e5;
const int P_I_MAX = 1e9;
const int Q_I_MAX = 1e9;
const int R_I_MAX = 1e9;

const int RED = 1;
const int GREEN = 2;
const int WHITE = 3;

int X, Y, A, B, C;
vector<int> p;
vector<int> q;
vector<int> r;

vector<pair<int, int>> v;

int main() {
  cin >> X >> Y >> A >> B >> C;
  p = vector<int>(A);
  REP(i, A) cin >> p[i];
  q = vector<int>(B);
  REP(i, B) cin >> q[i];
  r = vector<int>(C);
  REP(i, C) cin >> r[i];

  v = vector<pair<int, int>>(A + B + C);
  REP(i, A) v[i] = { p[i], RED };
  REP(i, B) v[A + i] = { q[i], GREEN };
  REP(i, C) v[A + B + i] = { r[i], WHITE };

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll ans = 0;
  int allCnt = 0;
  int rCnt = 0;
  int gCnt = 0;
  REP(i, v.size()) {
    if (allCnt >= X + Y) break;
    int x = v[i].first;
    int t = v[i].second;
    if (t == RED && rCnt >= X) continue;
    if (t == GREEN && gCnt >= Y) continue;
    ans += x;
    allCnt++;
    if (t == RED) rCnt++;
    if (t == GREEN) gCnt++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6736
n = int(input())

data = []
for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b])

data.sort(key = lambda x: x[1])
flag = True
sum = 0
for i in range(n):
    sum += data[i][0]
    if sum > data[i][1]:
        flag = False
        break
print("Yes" if flag == True else "No")

Measured memory_bytes: 38028
using System;
using System.Text;

public class Program
{
    static void Main()
    {
        var o = Console.ReadLine();
        var e = Console.ReadLine();
        var sb = new StringBuilder();
        var oIndex = 0;
        var eIndex = 0;
        for (int i = 0; i < o.Length + e.Length; i++)
        {
            if (i % 2 == 0)
            {
                sb.Append(o[oIndex]);
                oIndex++;
            }
            else
            {
                sb.Append(e[eIndex]);
                eIndex++;
            }
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#define INF 1<<28
using namespace std;

int main(){

  int n;
  int a,b,c;

  while(cin >> n, n){

    int ans1 = INF;
    int  ans2 = INF;
    double p = INF,q = INF;

    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      double k = (double)b/100;
      double d = c/(k*k);

      if(p > abs(22-d)){
	p = abs(22-d);
	ans1 = a;
      }

      else if(p == abs(22-d) && ans1 > a) ans1 = a;

    }
    cout << ans1 << endl;

  }
}

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

using namespace std;

int main()
{
    long long a,b,x;
    cin >> a >> b >> x;
    long long ans = b/x;
    long long ans2 = a/x;
    ans = ans-ans2;
    if(a%x == 0)
        ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>

using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	string str;
	vector<string> v;

	for (int i = 0; i < n; i++)
	{
		cin >> str;
		v.push_back(str);
	}
	sort(v.begin(), v.end());

	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i];
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 20;
int N, W;
int dp[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> W;
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1, w, v; i <= N; i++) {
        cin >> w >> v;
        for (int j = 1e5; j >= v; j--)
            dp[j] = min(dp[j], dp[j - v] + w);
    }
    for (int i = 1e5; i >= 0; i--) {
        if (dp[i] <= W) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <climits>
using namespace std;

#define REPI(i,a,b) for (ll i=(a);i<(b);i++)
#define REP(i,n) REPI(i,0,n)

typedef long long int ll;

int SURP = 1000000007;

int ceil(int a,int b){
	return (a+b-1)/b;
}

ll gcd(ll a,ll b){
	ll p;

	if (b > a){
		p = a;
		a = b;
		b = p;
	}

	while(b != 0){
		p = a % b;
		a = b;
		b = p;
	}
	return a;
}

int main(){
	ll N,x;
	cin >> N >> x;
	ll a[N];
	REP(i,N) cin >> a[i];

	ll ret = 0;
	if(a[0] > x){
		ret += a[0] - x;
		a[0] = x;
	}
	REPI(i,1,N){
		if(a[i] + a[i-1] > x){
			ret += a[i] - x + a[i-1];
			a[i] = x - a[i-1];
		}
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz hxr
#define ll long long
#define ull unsigned ll
int n, a[100005];
int main() {
	scanf("%d", &n);
	for (int i=0; i<n; i++)
		scanf("%d", &a[i]);
	int mx=a[0], mn=a[0];
	for (int i=1; i<n; i++) {
		mx=max(mx, a[i]);
		mn=min(mn, a[i]);
	}
	if (mx-mn>1) {
		puts("No");
		return 0;
	}
	int c1=0, c2=0;
	for (int i=0; i<n; i++) {
		if (a[i]==mx) c1++;
		if (a[i]==mn) c2++;
	}
	if (mx!=mn) {
		if (c2>=mx) {
			puts("No");
			return 0;
		}
		if (c1/(mx-c2)<2) {
			puts("No");
			return 0;
		}
		puts("Yes");
	} else {
		bool f1=false, f2=false;
		if (n/mx>1) {
			f1=true;
		}
		if (mn==n-1) {
			f2=true;
		}
		if (f1||f2)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}

Measured memory_bytes: 640
/*
  Contest 064
  B - Traveling AtCoDeer Problem
  Rakesh Kumar --> 31/08/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int n = 0;
    std::cin >> n;
    int a = 0;
    std::cin >> a; --n;
    int min = 0, max = 0;
    min = max = a;
    while (n--) {
        std::cin >> a;
        min = std::min(a, min);
        max = std::max(a, max);
    }
    std::cout << max - min << std::endl;

    return 0;
}


Measured memory_bytes: 3496
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
typedef pair<int, int>P;

int ctoi(char s) {
	return s - '0';
}

int main() {
	int n;
	cin >> n;
	long double x;string u;
	long double ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u == "JPY")
			ans += x;
		else {
			ans += 380000.0 * x;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
stack = [0]
while True:
  if len(stack) <= 0:
    break
  i = stack.pop()
  if i == len(S):
    print('YES')
    exit()
  if i+5 > len(S):
    continue
  if S[i:i+5] == 'dream':
    stack.append(i+5)
  if S[i:i+5] == 'erase':
    stack.append(i+5)
  if i+6 <= len(S):
    if S[i:i+6] == 'eraser':
      stack.append(i+6)
  if i+7 <= len(S):
    if S[i:i+7] == 'dreamer':
      stack.append(i+7)
print('NO')

Measured memory_bytes: 3504
#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 max=0;
	int min=0;
	for(int i=0;i<n;i++){
		if(a[i]>max)max=a[i];
		if(a[i]<min)min=a[i];
		if(min==0)min=a[i];
	}
	cout<<max-min<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    n, q = map(int, input().split())

    stx = []
    tmp = set([])

    for _ in range(n):
        s,t,x = map(int, input().split())
        stx.append((s,t,x))
        tmp.add(x-t)
        tmp.add(x-s)

    d = {}
    for i in range(q):
        di = -int(input())
        tmp.add(di)
        d[di] = i

    stx.sort(key = lambda x:x[2])

    v2i = {}

    for i, v in enumerate(sorted(tmp)):
        v2i[v] = i

    l = [1] * (len(tmp) + 1)

    for di in d:
        l[v2i[di]] = di
            

    #####単位元######
    ide_ele_min = 1

    #num_min:n以上の最小の2のべき乗
    N = len(l)

    num_min =2**(N-1).bit_length()
    seg_min=[ide_ele_min]*2*num_min

    def init_min(init_min_val):
        #set_val
        for i in range(N):
            seg_min[i+num_min-1]=init_min_val[i]    
        #built
        for i in range(num_min-2,-1,-1) :
            seg_min[i]=min(seg_min[2*i+1],seg_min[2*i+2]) 
    
    def update_min(k,x):
        k += num_min-1
        seg_min[k] = x
        while k:
            k = (k-1)//2
            seg_min[k] = min(seg_min[k*2+1],seg_min[k*2+2])
        
    def query_min(p,q):
        if q<=p:
            return ide_ele_min
        p += num_min-1
        q += num_min-2
        res=ide_ele_min
        while q-p>1:
            if p&1 == 0:
                res = min(res,seg_min[p])
            if q&1 == 1:
                res = min(res,seg_min[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = min(res,seg_min[p])
        else:
            res = min(min(res,seg_min[p]),seg_min[q])
        return res



    init_min(l)
    ans = [-1] * q

    for s, t, x in stx:
        l = v2i[x-t] + 1
        r = v2i[x-s] + 1
        v = query_min(l, r)
        while v != 1:
            i_d = d[v]
            i_sg = v2i[v]
            ans[i_d] = x
            update_min(i_sg, 1)
            v = query_min(l, r)

    for ansi in ans:
        print(ansi)
            
if __name__ == '__main__':
    main()



Measured memory_bytes: 171324
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

let solve ans w v =
  let (ans, _, xs) = Array.fold_left (fun (ans, j, xs) c -> match xs with
    | [] -> (ans, j + 1, [(c, j)])
    | (ch, _) :: _ ->
      if ch = c then (ans, j + 1, xs)
      else if ch < c then (ans, j + 1, (c, j) :: xs)
      else
        let rec f ans k = function
          | [] -> (ans, j + 1, [(c, k)])
          | (ch, cj) :: tl as ys ->
            if ch >= c then f (if ch * (j - cj) > ans then ch * (j - cj) else ans) cj tl
            else (ans, j + 1, (c, k) :: ys) in
        f ans j xs)
    (ans, 0, [])
    v in
  List.fold_left (fun acc (ch, cj) -> if ch * (w - cj) > acc then ch * (w - cj) else acc) ans xs

let () =
  match IO.read_ns () with
  | [h; w] ->
    let s = Array.make w 0 in
    let t = Array.make w 0 in
    let rec doit i ans =
      if i = h then ans
      else begin
        IO.read_ns () |> List.iteri (fun j e -> t.(j) <- if e = 1 then 0 else s.(j) + 1);
        Array.iteri (fun i e -> s.(i) <- e) t;
        solve ans w t |> doit (i + 1)
      end in
    doit 0 0 |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 5044
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    long N,X,sum=0;
    cin >> N;
    X = N;
    while (X != 0) {
        sum += X% 10;
        X /= 10;
    }

    cout << ((N%sum == 0) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    while(cin >> n){
        if(n == 0)  break;
        int cnt = 0;
        int x, y;
        for(int i = 2; (n/i) - (i/2) >= 0; i++){
            x = n / i; 
            y = x;
            if(i % 2 == 0){
                for(int j = 0; j < (i/2); j++){
                    x++;
                    y += x;
                }
                x = n / i;
                for(int j = 1; j < (i/2); j++){
                    x--;
                    y += x;
                }
            }
            else{
                if(x - (i/2) <= 0)  continue;
                for(int j = 0; j < (i/2); j++){
                    x++;
                    y += x;
                }
                x = n / i;
                for(int j = 0; j < (i/2); j++){
                    x--;
                    y += x;
                }
            }
            if(y == n)  cnt++;
        }
        cout << cnt << endl;
        
        
    }
    return 0;
}



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            String s = in.next();
            char[] cs = s.toCharArray();
            long count = 0;
            long countA = 0;
            for (int i = 0; i < cs.length;) {
                if (cs[i] == 'A') {
                    countA++;
                    i++;
                    continue;
                }
                if (i + 1 < cs.length && cs[i] == 'B' && cs[i + 1] == 'C') {
                    count += countA;
                    i += 2;
                    continue;
                }
                countA = 0;
                i++;
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 26552
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10 ** 10] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    for j in range(1, K+1):
        if i-j < 0:
            continue
        if dp[i] > dp[i-j] + abs(h[i] - h[i-j]):
            dp[i] = dp[i-j] + abs(h[i] - h[i-j])

print(dp[N-1])


Measured memory_bytes: 52448
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int A=0,B=0,C=0;
    cin >> A >> B >> C;
    cout << (C-A+B>0?C-A+B:0) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)       for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<vector<int>> d(n, vector<int>(2));
    rep(i, n)rep(j, 2) cin >> d[i][j];
    for(int i = 0; i < n-2; ++i){
        if( d[i][0] == d[i][1] &&
            d[i+1][0] == d[i+1][1] &&
            d[i+2][0] == d[i+2][1] ){
                cout << "Yes" << endl;
                return 0;
            }
    }

    cout << "No" << endl;

return 0;
}

Measured memory_bytes: 3672
import static java.lang.System.*;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if(h == 0 && w == 0) {
				break;
			}
			for(int a = 1; a <= h; a++) {
				for(int b = 1; b <= w; b++) {
					if(a > 1 && a < h && b > 1 && b < w) {
						out.print(".");
					}else{
						out.print("#");
					}
				}
				out.println();
			}
			out.println();
		}
	}
}


Measured memory_bytes: 34644
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

int N, K; cin >> N >> K;
VI a(N); invec(a);
VI beauties = a;
rep(i, 0, N) {
    i64 ai = a[i];
    rep(j, i+1, N){
        beauties.push_back(ai + a[j]);
        ai += a[j];
    }
}
i64 maxi = log2(*max_element(ALL(beauties)));
i64 ans = 0;
Rrep(i, maxi, 0){
    i64 bit = 1LL << i;
    VI b;
    for(i64 x: beauties) if (x & bit) b.push_back(x);
    if (K <= b.size()){
        beauties = b;
        ans |= bit;
    }
}

cout << ans << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 6360
import java.util.*;
 
public class Main {
	public static void main(String args[] ) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = Integer.valueOf ( sc.nextLine().trim() ) ;

		List<Boolean> list0 = Arrays.asList( false , false ) ;
		
		int mod = 1000000007 ;
		Map<List<Boolean>,Long> map = new HashMap<>() ; 
		map.put( list0 , 1L ) ;
		for ( int j=0 ; j<n ; j++ ) {
			Map<List<Boolean>,Long> map2 = new HashMap<>() ; 
			for ( List<Boolean> list  : map.keySet() ) {

				List<Boolean> list1 = Arrays.asList ( true , list.get(1).booleanValue() ) ;
				long d = map2.getOrDefault( list1 , 0L )  + map.get( list ).longValue() ;
				map2.put( list1 , d % mod ) ;

				list1 = Arrays.asList ( list.get(0).booleanValue() , true ) ;
				d = map2.getOrDefault( list1 , 0L )  + map.get( list ).longValue() ;
				map2.put( list1 , d % mod ) ;

				list1 = list ;
				d = map2.getOrDefault( list1 , 0L )  + map.get( list ).longValue() * 8 ;
				map2.put( list1 , d % mod ) ;

			}
			map = map2 ;
		}
		List<Boolean> list2 = Arrays.asList( true , true ) ;
		long d = map.getOrDefault( list2 , 0L ) ;
		System.out.println( d ) ;
	}
}

Measured memory_bytes: 50420
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e2 + 10, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vii v, ans;
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n;
	cin >> n;
	lp(i,1,n)
	{
		int x;
		cin >> x;
		v.pb( { x, i });
	}
	bool isn = false, isp = false;
	while (!isn && !isp) {
		sort(all(v));
		int x = v[0].F;
		int y = v.back().F;
		if (x <= 0 && y <= 0) {
			isn = true;
			continue;
		}
		if (x >= 0 && y >= 0) {
			isp = true;
			continue;
		}
		if (abs(x) > abs(y)) {
			v.back().F += v[0].F;
			ans.pb( { v[0].S, v.back().S });
		} else {
			v[0].F += v.back().F;
			ans.pb( { v.back().S, v[0].S });
		}
	}
	if (isn) {
		lp2(i,n,2)
			ans.pb( { i, i - 1 });
	} else {
		lp(i,2,n)
			ans.pb( { i - 1, i });
	}
	cout << ans.size() << "\n";
	for (auto u : ans)
		cout << u.F << " " << u.S << "\n";
	return 0;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())


def main():
    N = ii()
    a = [ii() for i in range(N)]
    now = 0
    for i in range(N+1):
        if now == 1:
            print(i)
            return
        now = a[now]-1
    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 94416
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int f=0;
	if((a==b)||(a==c)||(b==c)){
		f=1;
		if((a==b)&&(a==c)&&(b==c)){
			f=0;
		}
			
	}	
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//答え見た
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  int count=0;
  for(int i=0;i<n;i++){
    if(vec.at(i) != i+1){
      count++;
     }
  }
  if(count>2){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
	long long n, m[5], ans = 0;
	
	cin >> n;
	
	for (int i = 0; i < 5; i++) {
		cin >> m[i];
	}
	
	for (int i = 4; i > 0; i--) {
		for (int j = 0; j < i; j++) {
			if (m[j] > m[j + 1]) {
				long long tmp = m[j];
				m[j] = m[j + 1];
				m[j + 1] = tmp;
			}
		}
	}
  
	ans = n / m[0] + 5;
  
  if (n % m[0] == 0) {
    ans--;
  }
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 5010;
const int INF = 1e9 + 7;
int N;
vector<int> V[1010];
int X[1010];
int b[1010][2][MC];

void mn(int &s , int t){
	s = min(s,t);
}

int dfs(int p , int q){
	int t = 0;
	fill(b[q][0],b[q][0]+MC,INF);
	b[q][0][0] = 0;
	for(auto u : V[q]){
		int z = dfs(q,u);
		if(z<0) return -1;
		fill(b[q][(t+1)%2],b[q][(t+1)%2]+MC,INF);
		repp(i,0,X[q]+1){
			if(i+z<=X[q]) mn(b[q][(t+1)%2][i+z],b[q][t%2][i]+X[u]);
			if(i+X[u]<=X[q]) mn(b[q][(t+1)%2][i+X[u]],b[q][t%2][i]+z);
		}
		++t;
	}
	int m = INF;
	repp(i,0,X[q]+1) mn(m,b[q][t%2][i]);
	if(m == INF) m = -1;
	return m;
}

int main(){
	cin >> N;
	repp(i,1,N){
		int P;
		cin >> P;
		V[P].PB(i+1);
	}
	repp(i,1,N+1){
		cin >> X[i];
	}
	cout << (dfs(-1,1)<0?"IMPOSSIBLE":"POSSIBLE") << endl;
	return 0;
}


Measured memory_bytes: 39296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
    vector<P> res;
    for (long long p = 2; p * p <= n; ++p)
    {
        if (n % p != 0)
            continue;
        int num = 0;
        while (n % p == 0)
        {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1)
        res.push_back(make_pair(n, 1));
    return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return gcd(y, x % y);
    }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int x;
    cin >> x;
    int ans = 0;
    while (x >= 500)
    {
        x -= 500;
        ans += 1000;
    }
    while (x >= 5)
    {
        x -= 5;
        ans += 5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Ans = 0
for i in range(N):
    if A[i] + A[i+1] < B[i]:
        Ans += A[i] + A[i+1]
        A[i+1] = 0
    elif A[i] >= B[i]:
        Ans += B[i]
    else:
        Ans += B[i]
        A[i+1] -= B[i] - A[i]
print(Ans)

Measured memory_bytes: 24136