akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
ll sum(ll l, ll r) {
    return (l + r) * (r - l + 1) / 2;
}
/* main */
int main(){
    int N, K;
    cin >> N >> K;

    mint ans = 0;
    for (int i = K; i <= N + 1; i++) {
        ll l = sum(0, i - 1), r = sum(N - i + 1, N);
        ans += r - l + 1;
    }
    cout << ans << '\n';
}


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

int main(){
  int N;
  cin>>N;
  string S,T;
  string u;
  cin>>S;
  cin>>T;
  string ans;
  for(int i=0;i<N;i++){
    ans +=S[i];
    ans +=T[i];
      
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <complex>
#include <functional>
#include <cmath>

using namespace std;

using ull = unsigned long long;
using ll = long long;


int main(){

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

	vector<string> isUnuse;
	for (int i = 0; i < K; i++){
		string temp;
		cin >> temp;
		isUnuse.emplace_back(temp);
	}

	while (1){
		string str = to_string(N);
		int count = 0;
		for (auto&& a : isUnuse){
			if (strstr(str.c_str(), a.c_str()) == NULL){
				count++;
			}
			else{
				N++;
				break;
			}
		}
		if (count == isUnuse.size()){
			cout << str << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  cout << a * b / 2 << endl;
}


Measured memory_bytes: 3640
import java.util.Scanner;

// https://atcoder.jp/contests/abc167/tasks/abc167_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		sc.close();

//		long startTime = System.currentTimeMillis();

		long ans = 0L;

		if(a>=k) {
			ans = ans + 1L*k;
			System.out.println(ans);
			return;
		}else {
			ans = ans + 1L*a;
			k = k-a;
			if(b>=k) {
				System.out.println(ans);
				return;
			}else {
				k = k-b;
				if(c>=k) {
					ans = ans - 1L*k;
					System.out.println(ans);
					return;
				}else {
					ans = ans - 1L*c;
					System.out.println(ans);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 27032
import numpy as np

A, B, H, M = list(map(int, input().split()))

long_rad = (H % 12) / 12. + M / (12. * 60)
short_rad = M / 60.

sub_rad = (np.abs(long_rad - short_rad))
if sub_rad > 1 / 2.:
    sub_rad = 1 - sub_rad

x = (A * np.cos(2 * np.pi * sub_rad))
y = (A * np.sin(2 * np.pi * sub_rad))
print(np.sqrt(y ** 2 + (B - x) ** 2))


Measured memory_bytes: 27204
#include <iostream>
#include <algorithm>
    
using namespace std;
    
int main() {
int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
if(x>=r&&x<=w-r&&y>=r&&y<=h-r)
cout << "Yes" << endl;
else
cout << "No" << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
    multiset < int > res;
    for (int i = 1; i <= n; ++i){
        auto to = res.lower_bound(a[i]);
        if (to == res.begin()) res.insert(a[i]);
        else {
            to--;
            res.erase(to);
            res.insert(a[i]);
        }
    }
    printf ("%d\n", sz(res));
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

ll comb(int n, int r)
{
    ll upper = 1, lower = 1;
    for (int i = 0; i < r; i++)
    {
        upper *= (n - i);
        lower *= (i + 1);
    }
    return upper / lower;
}

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    map<string, int> mp;
    rep(i, N)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        mp[s[i]]++;
    }
    ll ans = 0;
    for (auto m : mp)
    {
        ans += comb(m.second, 2);
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 18176
import sys
input = sys.stdin.readline
import bisect
N = int(input())
a = [-int(input()) for i in range(N)]
ls = []
res = 0
for elem in a:
    idx = bisect.bisect_right(ls,elem)
    if idx == res:
        ls.append(elem)
        res += 1
    else:
        ls[idx] = elem
print(res)


Measured memory_bytes: 47708
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  cin >> n >> m;
  vector<pair<ll, pll>> v;
  set<ll> t;
  unordered_map<ll, ll> mp, an;
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b >> c;
    v.pb(make_pair(c, pll(max(0LL, a - c), max(0LL, b - c))));
  }
  sort(all(v));
  rep(i, m) {
    cin >> tmp;
    mp[tmp] = i;
    t.insert(tmp);
  }
  t.insert(-inf);
  t.insert(inf);
  rep(i, n) {
    ll le = v[i].second.first, ri = v[i].second.second;
    auto it = t.lower_bound(le);
    while (*it < ri) {
      an[mp[*it]] = v[i].first;
      t.erase(*it);
      it = t.lower_bound(le);
    }
  }

  rep(i, m) {
    if(an[i]) cout << an[i] << endl;
    else cout << "-1" << endl;
  }

  return 0;
}

Measured memory_bytes: 31724
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n, d;
  cin >> n >> d;
  int m = 2*d+1; // 1人で見れる数
  cout << (n/m) + (n%m!=0) << endl;
}


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

int main(){
    ll n; 
    cin >> n;
    vector<string> S(n);
    rep(i,n) {
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end());

    ll ans = 0, kotae = 0;
    rep(i,n-1) {
        if (S[i] == S[i + 1]) {
            kotae++;
            ans += kotae;
        } else {
            kotae = 0;
        }
    }
    cout << ans << endl;
}



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

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
Matrix<T> matrix(int R, int C, T x = T()) { return Matrix<T>(R, vector<T>(C, x)); }

struct SparseTable
{
    int K;
    Matrix<int> jump;

    SparseTable(int N, int L, vector<int> locations)
    {
        K = 0; while (1<<K < N) K++;

        jump = matrix<int>(K+1, N);
        for (auto i = 0; i < N-1; i++)
        {
            auto one_day_max = lower_bound(begin(locations), end(locations), locations[i]+L+1) - begin(locations) - 1;
            jump[0][i] = static_cast<int>(one_day_max);
        }
        jump[0][N-1] = N-1;

        for (auto k = 1; k <= K; k++) for (auto i = 0; i < N; i++)
            jump[k][i] = jump[k-1][jump[k-1][i]];
    }

    int query(int i, int j)
    {
        auto days = 0;
        for (auto k = K; k >= 0; k--) if (jump[k][i] < j)
        {
            i = jump[k][i];
            days += 1<<k;
        }
        return days+1;
    }
};

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

    auto locations = vector<int>(N);
    for (auto& x : locations) cin >> x;

    int L; cin >> L;

    auto table = SparseTable(N, L, locations);

    int Q; cin >> Q;
    for (auto i = 0; i < Q; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);

        cout << table.query(a, b) << endl;
    }
}


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

using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    map<char, int> ch;
    cin >> s;
    for (char c : s) {
        ++ch[c];
    }

    bool ok = true;
    for (auto p : ch) {
        if (p.second % 2 != 0)
            ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;

}



Measured memory_bytes: 256
#define FOR(i, a, b) for(int i=a; i<b; i++)
#include<cstdio>
#include<algorithm>
#include<utility>
#include<string>
#include<cstdlib>

int main(){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    while(true){
        c -= b;
        if(c<=0){
            printf("Yes\n");
            break;
        }
        a -= d;
        if(a<=0){
            printf("No\n");
            break;
        }
    }

    return 0;
}

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


int main(void){
    int H,W,i,j;
    while(1){
        scanf("%d%d",&H,&W);
        if(H==0 && W==0)
            break;
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i==0 || i==H-1){
                printf("#");
                }
                if((j==0 || j==W-1)&&i!=0&&i!=H-1){
                printf("#");
                }
                if(j!=1&&j!=(W-1)&&i!=0&&i!=(H-1)){
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
vector<int> graph[100000];
vector<tuple<int, int, int>> ans;
bool isReach[100000] = {false};
void dfs(int node, int par, int pColor) {
	if (isReach[node]) {
		return;
	}
	isReach[node] = true;
	// printf("node:%d\n", node);
	int color = 1;
	for (int i = 0; i < graph[node].size(); i++) {
		int nn = graph[node][i];
		if (par == nn)
			continue;
		if (color == pColor)
			color++;
		ans.push_back(make_tuple(nn, node, color));
		dfs(nn, node, color);
		color++;
	}
	return;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[100000], b[100000];
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		graph[a[i]].push_back(b[i]);
		graph[b[i]].push_back(a[i]);
	}
	int k = 0;
	for (int i = 0; i < n; i++) {
		k = max(k, (int)graph[i].size());
	}
	dfs(0, -1, -1);
	cout << k << endl;
	map<pair<int, int>, int> t;
	for (int i = 0; i < ans.size(); i++) {
		t[pair<int, int>(get<0>(ans[i]), get<1>(ans[i]))] = get<2>(ans[i]);
		t[pair<int, int>(get<1>(ans[i]), get<0>(ans[i]))] = get<2>(ans[i]);
	}
	for (int i = 0; i < n - 1; i++) {
		cout << t[pair<int, int>(a[i], b[i])] << endl;
	}
	return 0;
}

Measured memory_bytes: 23312
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(5);
for (int i = 0; i < 5; i++) {
  cin >> vec.at(i);
}
  for (int i = 0; i < 5; i++){
    if (vec.at(i)==0) {
      cout << i+1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 3612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    string a,b,c; cin>>a>>b>>c;
    if(a[a.size()-1]!=b[0]){
        cout<<"NO"<<endl;
    }
    else if(b[b.size()-1]!=c[0]){
        cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;
}





Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author test
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc177_b solver = new abc177_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc177_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            String T = in.next();

            int mincnt = 1001;
            for (int i = 0; i < (S.length() - T.length()) + 1; i++) {
                int umcnt = 0;
                for (int j = 0; j < T.length(); j++) {
                    if (S.charAt(i + j) != T.charAt(j)) {
                        umcnt++;
                    }
                }
                mincnt = Integer.min(mincnt, umcnt);
            }
            out.println(mincnt);
        }

    }
}



Measured memory_bytes: 35912
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

Sum = 0
for i in range(N):
    Sum += B[A[i] - 1]
    if i >= 1 | A[i] - A[i-1] == 1:
        Sum += C[A[i] - 2]
print(Sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    vector<int> t(5);
    rep(i, 5) cin >> t[i];
    vector<int> loss;
    rep(i, 5) loss.push_back((t[i] % 10 == 0 ? 0 : 10 - t[i] % 10));
    sort(loss.begin(), loss.end());
    int ans = 0;
    rep(i, 5) ans += t[i];
    rep(i, 4) ans += loss[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll N, x;
ll a[100010];

int main()
{
  scanf( "%lld%lld", &N, &x );

  rep( i, N )
    scanf( "%lld", a+i );

  ll ans = 0;

  repi( i, 1, N )
  {
    ll diff = a[i-1]+a[i]-x;

    if( diff <= 0 )
      continue;

    if( a[i] >= diff )
    {
      a[i] -= diff;
    }
    else
    {
      a[i] = 0;
      a[i-1] -= diff-a[i];
    }

    ans += diff;
  }

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MOD=1e9+7;

int32_t main()
{
   IOS
   const int N=1e5;
   int a[N+1][3];
   int dp[N+1][3];
   int n;cin>>n;
   for(int i=1;i<=n;i++)
   for(int j=0;j<3;j++)
   cin>>a[i][j];
   
   dp[1][0]=a[1][0];
   dp[1][1]=a[1][1];
   dp[1][2]=a[1][2];
   
   for(int i=2;i<=n;i++){
	   for(int j=0;j<3;j++)
	   dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
   }
   
   cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
   
}


Measured memory_bytes: 4992
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    s = [input() for _ in range(n)]

    ac = 0
    wa = 0
    tle = 0
    re = 0

    for i in s:
        if i == "AC":
            ac += 1
        elif i == "WA":
            wa += 1
        elif i == "TLE":
            tle += 1
        elif i == "RE":
            re += 1

    print("AC x", ac)
    print("WA x", wa)
    print("TLE x", tle)
    print("RE x", re)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 77576
package main

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

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	max := 0
	min := 10000000000
	for i := range arr {
		sc.Scan()
		arr[i], _ = strconv.Atoi(sc.Text())
		if arr[i] > max {
			max = arr[i]
		}
		if arr[i] < min {
			min = arr[i]
		}
	}
	fmt.Println(max - min)
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

long long INF = 1e9;
ll dp[55][50*50*2];
int main(){
  ll n,a,i,j;
  cin >> n >> a;
  vector<ll> v(n);
  for(i=0;i<n;i++){
    cin >> v[i];
    v[i]-=a;
  }
  for(i=0;i<50*50*2;i++){
    dp[0][i]=0;
  }
  for(i=0;i<n;i++){
    for(j=0;j<50*50*2;j++){
      dp[i+1][j]=dp[i][j];
    }
    dp[i+1][2500+v[i]]++;
    for(j=0;j<50*50*2;j++){
      if(j+v[i]>=0 && j+v[i]<50*50*2)dp[i+1][j+v[i]]+=dp[i][j];
    }
  }
  cout << dp[n][2500] << endl;
  return 0;
}


Measured memory_bytes: 2176
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)

@fact = Hash.new
def fact(n)
  @fact[n] if @fact[n]

  return 1 if n == 0

  @fact[n] = n * fact(n - 1)
end

def ncr(n, r)
  return 0 if n < r

  fact(n) / (fact(r) * fact(n - r))
end

puts ncr(n, 2) + ncr(m, 2)


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A > 0 && C > 0){
        if(C > 0){
             C = C - B;
             if(C <= 0){
                 cout << "Yes" << endl;
                 break;
             }
        }
        if(A > 0){
             A = A - D;
             if(A <= 0){
                 cout << "No" << endl;
                 break;
             }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
function main()
  
  a = parse(Int,readline())
  b = parse(Int,readline())
  c = parse(Int,readline())
  d = parse(Int,readline())
  e = parse(Int,readline())
  k = parse(Int,readline())
  
  Coo = [a,b,c,d,e,]
  
  check = true
  
  for i in Coo, j in Coo
    
    if abs(i-j) > k
      check = false
    end
    
  end
  
  if check == true
    println("Yay!")
  else
    println(":(")
  end
  
end

main()

Measured memory_bytes: 167512
#include<bits/stdc++.h>
using namespace std;
long long dp[1010];
int main() {
    int n;
    cin>>n;
    dp[0] = 2;
    for(int i = 1;i <= n;i++) {
        dp[i] = dp[i - 1] * 2 + 2;
    }
    cout<<dp[n];
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>

using namespace std;

int main(void)
{
	long long int count[10] = { 0, };
	long long int H, W, N;
	long long int a, b;
	map <pair<long long int, long long int>, int> painted;
	cin >> H >> W >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a >> b;
		for (long long int j = a - 2; j <= a; j++)
		{
			for (long long int k = b - 2; k <= b; k++)
			{
				if (j >= 1 && j <= H - 2 && k >= 1 && k <= W - 2)
				{
					painted[make_pair(j, k)] += 1;
				}
			}
		 }
	}
	//아무것도 색칠되지 않았다고 설정.
	count[0] = (H - 2)*(W - 2);

	for (auto it = painted.begin(); it != painted.end(); it++)
	{
		count[it->second]++;
	}

	for (int i = 1; i < 10; i++)
	{
		count[0] -= count[i];
	}

	for (int i = 0; i < 10; i++)
	{
		cout << count[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 56448
/// Bismillahir Rahmanir Rahim
/// S. M. Shakir Ahsan Romeo

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

const double PI = acos(-1.0);

typedef long long lng;
typedef unsigned long long ulng;
typedef double db;
typedef pair < int, int >  pii;
typedef vector < pii >  vpii;
//typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

inline int getint()
{
    int x;
    scanf("%d", &x);
    return x;
}
#define II getint()

inline long long getlng()
{
    long long x;
    scanf("%lld", &x);
    return x;
}
#define LL getlng()

int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};


void solve();
#define theromeo421 main()
#define segtree int lft = node << 1, rgt = lft | 1, mid = (b + e) >> 1;
#define mem(x, y) memset((x), (y), sizeof (x));
#define sz(x) ((int)x.size())
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define pr1(x) cout << x << endl
#define pr2(x,y) cout << x << ' ' << y << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define repstl(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define forcon(pp , qq) for(const auto& pp : qq)
#define all(x) (x).begin(), (x).end()
#define Unique(x) sort(all(x)); x.erase(unique(all(x)), x.end()); /// x needs to be sorted first
#define pb push_back
#define wait system("pause")
#define xx first
#define yy second
#define dbg(x) cerr << #x << "=" << x << endl;
#define dbg2(x, y) cerr << #x << "=" << x << ", " << #y << "=" << y << endl;
#define read(a) freopen(a, "r", stdin);
#define write(a) freopen(a, "w", stdout);
#define prv(v) rep(i, sz(v)) cout << v[i] << " \n"[i + 1 == v.size()];
#define Case int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas)
#define pf printf
#define sf scanf
#define MP make_pair
#define endl '\n'
const double eps = (double)1e-9;


int theromeo421
{
    /// PLEASE HACK my code, I am error prone.
    /// Your hack can save me from the cruel hand of system testing. :) :P ;)
    solve();
#ifdef romeo
    cerr << "\nElapsed time: " << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
#endif // romeo
    return 0;
}


void solve()
{
    string a, b; cin >> a >> b; string c = a + b; lng x = atoll(c.c_str());
    lng y = sqrt(x); if(y * y == x) cout << "Yes"; else cout << "No"; cout << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))
DP = []
for i in range(min(N, K + 1)):
    DP.append(abs(H[0] - H[i]))
for i in range(K + 1, N):
    diff = float("inf")
    for d in range(1, K + 1):
        diff = min(diff, DP[-d] + abs(H[i - d] - H[i]))
    DP.append(diff)
print(DP[-1])


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

int main() {
	long long int a, x, y, i;
	long long int b[200000], c[200000];
	cin >> a;
	for(i = 0; i < a; i++) {
		c[i] = 0;
	}
	for(i = 1; i < a; i++) {
		cin >> b[i];
		x = b[i] - 1;
		c[x] = c[x] + 1;
	}
	for(i = 0; i < a; i++) {
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6764
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;


int main()
{
	int x, n, min = 200, q = 200;
	cin >> x >> n;
	vector<int> p(n + 1);
	rep(i, n)
	{
		cin >> p[i];
	}
	p[n] = 200;
	sort(p.begin(), p.end());
	int j = 0;
	reps(i, 0, 102)
	{
		if (i == p[j])
		{
			++j;
			continue;
		}
		if (min > abs(x - i))
		{
			min = abs(x - i);
			q = i;
		}
	}
	cout << q << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;

ll a[maxn], b[maxn], c[maxn], d[maxn];
int n;

int process(ll l, ll r) {
  l--;
  ll ret = 0;
  int i = 1, j = n;
  while (i <= n) {
    while (j > 0 && a[i] + b[j] > l) --j;
    ret -= j;
    ++i;
  }
  i = 1; j = n;
  while (i <= n) {
    while (j > 0 && a[i] + b[j] > r) --j;
    ret += j;
    ++i;
  }
  return (ret % 2);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }

  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
  }
  int ans = 0;
  for (int k = 0; k <= 29; ++k) {
    ll T = (1 << k);
    for (int i = 1; i <= n; ++i) {
      a[i] = c[i] % (T<<1);
      b[i] = d[i] % (T<<1);
    }
    sort(a+1, a+n+1); sort(b+1, b+n+1);
    int num = process(T, 2*T-1) + process(3*T, 4*T-1);
    num = num % 2;
    if (num) ans = ans + (1 << k);
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 9880
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

int main() {
    long n, x;
    cin >> n >> x;
    VI ms;
    REP(i,n) {
        long m;
        cin >> m;
        ms.push_back(m);
    }
    
    for (auto m: ms) {
        x -= m;
    }
    sort(ms.begin(), ms.end());
    cout << n + x / ms.front() << endl;
}


Measured memory_bytes: 256
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush


def main():
    N, M, *A = map(int, open(0).read().split())
    H = [-i for i in A]
    heapify(H)
    pop_max, push_max = lambda A: -heappop(A), lambda A, x: heappush(A, -x)
    for _ in range(M):
        x = pop_max(H)
        push_max(H, x // 2)
    ans = -sum(H)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
def ja;  puts'Yes'; exit end
def nein; puts'No'; exit end

N = gets.to_i
A,B = $<.map{|ln| ln.split.map(&:to_i) }

IA = (0...N).sort_by{|i| A[i] }
IB = (0...N).sort_by{|i| B[i] }

nein unless (0...N).all?{|i| A[IA[i]] <= B[IB[i]]  }
ja if (1...N).any?{|i| A[IA[i]] <= B[IB[i-1]] }

IIB = [nil]*N
IB.each_with_index{|i,j|
	IIB[i] = j
}

i,v,V = IA[0],0,[nil]*N
until V[i]
	V[i] = v+=1
	i = IA[IIB[i]]
end

v<N ? ja : nein


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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int[] nmx = ReadAndParseIntArr();
            int n = nmx[0];
            int m = nmx[1];
            int x = nmx[2];
            int[] tmpa = ReadAndParseIntArr();
            int[] a = new int[n + 1];
            for(int i=0;i<tmpa.Length;++i)
            {
                a[tmpa[i]] = 1;
            }
            int sum0 = 0;
            for(int i=0;i<=x;++i)
            {
                sum0 += a[i];
            }
            int sum1 = 0;
            for(int i=x;i<=n;++i)
            {
                sum1 += a[i];
            }
            int ans = Math.Min(sum0, sum1);
            Console.WriteLine(ans);
        }
        
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

struct students {
    long long i;
    long long a;
};

int my_sort(const void *v1, const void *v2)
{
    struct students *s1 = (struct students*)v1;
    struct students *s2 = (struct students*)v2;

    return( s1->a - s2->a );
}

int main(int argc, void **arg)
{
    long long n, i;
    struct students s[100000];

    scanf("%lld", &n);

    for (i = 0; i < n; i++)
    {
        s[i].i = i + 1;
        scanf("%lld", &s[i].a);
    }

    qsort(s, n, sizeof(struct students), my_sort);

    for (i = 0; i < n; i++)
    {
        printf("%lld ", s[i].i);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 3324
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll a,b;
    std::cin >> a>>b;
    std::cout << (a+b)%24 << std::endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){

			//H ??????????????????
			int H = sc.nextInt();
			//W ?¨????????????????
			int W = sc.nextInt();
			//?????¶??? H??¨W???0?????????????????´??? ??????
			if(H ==0 && W ==0){
				break;
			}
			//????????¨???
			for(int i = 0; i<H; i++){
				//?¨??????¨???
				for(int j =0; j<W; j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

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

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

    int t[N+1],x[N+1],y[N+1];
    int defTime = 0,defDistance = 0;
    bool canTraveling = true;

    //それぞれ0番目を初期化（初期位置時では0)
    t[0] = 0,x[0] = 0,y[0] = 0;
    for(int i = 1;i < N+1;i++){
        cin >> t[i] >> x[i] >> y[i];
        defTime = t[i] - t[i-1];
        defDistance = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
            
        if(defTime < defDistance){
            canTraveling = false;
        }else{
            if(defTime % 2 != defDistance % 2){
                canTraveling = false;
           }
        }
    }
    
    if(canTraveling == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#define N 100000
typedef struct{
    char name[11];
    int time_process;
    int time_count;
} queue_in;
void enqueue(queue_in data1);
void dequeue(queue_in data2);
queue_in A[N],B[N],tmp;
int first = 0;
int n;

int main(){
    int q,i,j,tmp_sort,k=0,count=0,tmp_i,flag;
    queue_in sortfor;
    scanf("%d%d",&n,&q);
    tmp_sort = n;
    for(i=0;i<n;i++){
        scanf("%s%d",A[i].name,&A[i].time_process);
    }
    while(n>0){
        if((A[first].time_process -q) <=0){
            A[first].time_count = (A[first].time_process) + count;
            count += A[first].time_process;
            B[k] = A[first];
            k++;
            dequeue(A[first]);
            continue;
        }
        A[first].time_process -= q;
        count += q;
        dequeue(A[first]);
        enqueue(tmp);
    }
    for(i=0;i<tmp_sort;i++){
        tmp_i = i;
        flag = 0;
        for(j=i;j<n;j++){
            if(B[j].time_count<B[tmp_i].time_count){
                tmp_i = j;
                flag = 1;
            }
        }
        if(flag==1){
            sortfor = B[i];
            B[i] = B[tmp_i];
            B[tmp_i] = sortfor;
        }
    }
    for(i=0;i<tmp_sort;i++){
        printf("%s %d\n",B[i].name,B[i].time_count);
    }
    return 0;
}

void enqueue(queue_in data1){
    if(n<N){
        A[(first+n) % N] = data1;
        n++;
    }
}
void dequeue(queue_in data2){
    if(n>0){
        tmp = data2;
        first = (first+1) % N;
        n--;
    }
}


Measured memory_bytes: 4612
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        static long n;
        static long k;
        static long[] a;

        public static void Answer()
        {
            var nk = IO.RSLong;
            n = nk[0];
            k = nk[1];
            a = IO.RSLong;

            if (k == 0)
            {
                WriteLine(a.Max());
                return;
            }

            long ng = 1;
            long ok = long.MaxValue - 1;

            while (ok - ng > 1)
            {
                long mid = (ok + ng) / 2;
                if (IsOK(mid))
                    ok = mid;
                else
                    ng = mid;
            }
            WriteLine(ok == 2 ? 1 : ok);
            //WriteLine(ng);
        }

        public static bool IsOK(long mid)
        {
            long totalCnt = 0;
            for (int i = 0; i < n; i++)
            {
                long cnt = (long)(a[i] / mid);
                if (a[i] % mid == 0) cnt--;
                totalCnt += cnt;
            }
            return totalCnt <= k;
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 45620
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int maxn = 1e5+5;
typedef long long ll;
int main(void)
{
	int X;
	scanf("%d", &X);
	ll ans = (X / 500LL) * 1000;
	X %= 500;
	ans += (X / 5LL) * 5;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	vector <int> v;
	for (int i = 0; i < 10; i++){
		int h;
		cin >> h;
		v.push_back(h);
	}
	sort(v.begin(), v.end(), greater<int>());
	for (int i = 0; i < 3;i++){
		cout <<v[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int C[]=new int[N-1];
		int S[]=new int[N-1];
		int F[]=new int[N-1];
		int z=0,y=0,time=0;
		while(z<N-1){
			C[z]=stdIn.nextInt();
			S[z]=stdIn.nextInt();
			F[z]=stdIn.nextInt();
			z++;
		}z=0;
		while(z<N-1){
			y=z;
			while(y<N-1){
				if(y==0)
					time+=C[y]+S[y];
				else{
					if(time>S[y]){
						if((time-S[y])%F[y]==0)
							time+=C[y];
						else
							time+=((time-S[y])/F[y]+1)*F[y]-(time-S[y])+C[y];
					}
					else
						time+=(S[y]-time)+C[y];
				}
				y++;
			}
			z++;
			System.out.println(time);
			time=0;
		}
		System.out.println(time);
	}

}

Measured memory_bytes: 26864
#include<bits/stdc++.h>
using namespace std;
int x,y,a,b,c;
priority_queue<long long,vector<long long>,greater<long long> > r;
priority_queue<long long,vector<long long>,greater<long long> > g;
priority_queue<long long> s;
int main()
{
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		int z;
		scanf("%d",&z);
		r.push(z);
	}
	for(int i=1;i<=b;i++)
	{
		int z;
		scanf("%d",&z);
		g.push(z);
	}
	for(int i=1;i<=c;i++)
	{
		int z;
		scanf("%d",&z);
		s.push(z);
	}
	while(r.size()>x)r.pop();
	while(g.size()>y)g.pop();
	for(int i=1;i<=c;i++)
	{
		if(r.top()>g.top()&&s.top()>g.top())g.pop(),g.push(s.top());
		else if(s.top()>r.top())r.pop(),r.push(s.top());
		s.pop();
	}
	long long sum=0;
	for(int i=1;i<=x;i++)
	{
		//cout<<r.top()<<" ";
		sum+=r.top();
		r.pop();
	}
	//cout<<endl;
	for(int i=1;i<=y;i++)
	{
		//cout<<g.top()<<" ";
		sum+=g.top();
		g.pop();
	}
	cout<<sum;
}


Measured memory_bytes: 3316
n=int(input())
num=[0]
ans=0
count=0
k=1
for i in range(n):
    a=int(input())
    num.append(a)

for i in range(n+1):
    k=num[k]
    count+=1
    if k==2:
        ans=1
        break
if ans==1:
    print(count)
else:
    print("-1")

Measured memory_bytes: 7088
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        char[] in = s.toCharArray();
        int count = 0;
        for (char c = 'a';c <= 'z';++c){
            ArrayList<String> subs1 = new ArrayList<>();
            for (int i = 0;i < in.length;++i){
                if(in[i] == c){
                    subs1.add(s.substring(i));
                }
            }
            Collections.sort(subs1);
            ArrayList<String> counted = new ArrayList<>();
            for (String ss:subs1){
                for (int i = 1;i <= ss.length();++i){
                    String kw = ss.substring(0,i);
                    if(!counted.contains(kw)){
                        counted.add(kw);
                        ++count;
                        if(count == k){
                            System.out.println(kw);
                            return;
                        }
                    }
                }
            }


        }
    }






}

Measured memory_bytes: 55252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

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

	int K;

	cin >> K;

	if (K % 2 == 1)
	{
		K = (K / 2)*(K / 2 + 1);
	}
	else
	{
		K = (K / 2)*(K / 2);
	}

	cout << K << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){

    int n, num;
    vector<int> vect;
    scanf("%d", &n);

    rep(i, 0, n){
        scanf("%d", &num);
        if(num%2!=0){
            cout << 0 << endl;
            break;
        }
        else{
            vect.push_back(num);
        }
    }
    int count = 0;
    if(vect.size()==n){
        bool flag = true;
        while(flag==true){
            rep(i,0,n){
                num = vect.at(i);
                if(num%2!=0){
                    flag = false;
                }
                else{
                    num = num/2;
                    vect[i] = num;
                }
            }
            if(flag==true) count++;
        }
        cout << count << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256