akhauriyash/Code-Regression huggingface dataset:
X = int(input())
fif = [i**5 for i in range(200)]
for i in range(len(fif)):
    B5 = fif[i] - X
    if abs(B5) in fif:
        index = fif.index(abs(B5))
        B = B5//abs(B5) * index
        break

print(i, B)

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

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

  vector<pair<int, int>> S(N);
  for (int i = 0; i < N; i++) {
    int a;
    int b;
    cin >> a >> b;
    S.at(i) = make_pair(a, b);
  }

  vector<pair<int, int>> C(M);
  for (int i = 0; i < M; i++) {
    int c;
    int d;
    cin >> c >> d;
    C.at(i) = make_pair(c, d);
  }

  int minv;
  int ans;
  for (int i = 0; i < N; i++) {
    int a, b;
    minv = 1001001001;
    tie(a, b) = S.at(i);
    for (int j = 0; j < M; j++) {
      int c, d;
      tie(c, d) = C.at(j);
      if(minv > abs(a - c) + abs(b - d)){
        minv = abs(a - c) + abs(b - d);
        ans = j+1;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 100 + 10 ;

int n , ar [ N ] ; 

int calc ( int x ) {
	int ret = 0 ;
	for ( int i = 0 ; i < n ; ++ i ) {
		ret += ( ar [ i ] - x ) * ( ar [ i ] - x ) ; 
	}
	return ret ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 0 ; i < n ; ++ i )
		cin >> ar [ i ] ;
	int res = 4e18 ;
	for ( int i = -200 ; i <= 200 ; ++ i )
		smin ( res , calc ( i ) ) ;
	cout << res << '\n' ; 
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  

  for(i = 1;i < n+1;i++){
    key = A[i];
    j = i - 1;
    
    while(j >= 0 && A[j] > key){
      
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
      
  
    }
    trace(A,n);
  }
    
    return 0;
}

Measured memory_bytes: 608
from collections import deque

S = input()
Q = int(input())

Query = [[0] * 3 for _ in range(Q)]
for i in range(Q):
    tmp = input().split()
    if tmp[0] == "1":
        Query[i][0] = 1
    elif tmp[0] == "2":
        Query[i][0] = 2
        Query[i][1] = int(tmp[1])
        Query[i][2] = tmp[2]

q = deque()
q.extend(S)
rev_flag = 0


for i in range(Q):
    if Query[i][0] == 1:
        rev_flag = (1 - rev_flag)
    else:
        if Query[i][1] == 1 and rev_flag == 0:
            q.appendleft(Query[i][2])
        elif Query[i][1] == 1 and rev_flag == 1:
            q.append(Query[i][2])
        elif Query[i][1] == 2 and rev_flag == 0:
            q.append(Query[i][2])
        elif Query[i][1] == 2 and rev_flag == 1:
            q.appendleft(Query[i][2])

if rev_flag == 1:
    q.reverse()
print("".join(list(q)))

Measured memory_bytes: 112868
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 2e5+5;
LL a[55][55] , dp[55][55];
LL MOD = 1e9+7;

void multiply(LL a[][55] , LL b[][55] , LL res[][55] , LL n)
{
        LL temp[n+2][n+2];
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= n ; j++)
                {
                        temp[i][j] = 0;
                        for(int k = 1 ; k <= n ; k++)
                        {
                                temp[i][j] = (temp[i][j]%MOD + (a[i][k]%MOD * b[k][j]%MOD)%MOD)%MOD;
                        }
                }
        }
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= n ; j++)
                {
                        res[i][j] = temp[i][j];
                }
        }
}

void getPow(LL y , LL n)
{
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= n ; j++)
                {
                        if(i == j) dp[i][j] = 1;
                        else dp[i][j] = 0;
                }
        }
        while(y > 0)
        {
                if(y%2)
                {
                        multiply(dp , a , dp , n);
                }
                y /= 2;
                multiply(a , a , a , n);
        }
}

int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        LL n,k;
        cin >> n >> k;
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= n ; j++)
                {
                        cin >> a[i][j];
                }
        }
        getPow(k,n);
        LL ans = 0;
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= n ; j++)
                {
                        ans = (ans%MOD + dp[i][j]%MOD)%MOD;
                }
        }
        if(ans < 0) ans += MOD;
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int x,y,z,i,j;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0) break;
	
	
		if(x>=y){
			printf("%d %d\n",y,x);
		}
		else{
			printf("%d %d\n",x,y);
		}
			
	}	
		
		
	return 0;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, q;
vector<int> g[N];
int counter[N];

void dfs(int v, int p = 0){
	counter[v] += counter[p];
	for(auto u:g[v]){
		if (u == p) continue;
		dfs(u, v);
	}
}
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> q;
	for(int i=1; i<n; i++){
		int u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	while(q--){
		int p, x; cin >> p >> x;
		counter[p] += x;
	}
	dfs(1);
	for(int i=1; i<=n; i++){
		cout << counter[i] << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 23552
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		string u,h;
		string a[50];
		int k = 1000;
		for (int i = 0; i < n; i++) {
			cin >> u;
			h = "";
			for (int i = 0; i < u.length(); i++) {
				if (i == 0) h += u[0];
				else if (u[i - 1] == 'a' || u[i - 1] == 'i' || u[i - 1] == 'u' || u[i - 1] == 'e' || u[i - 1] == 'o') {
					h += u[i];
				}
			}
			a[i] = h;
			k = max(k, (int)h.length());
		}
		int  m = -1;
		for (int i = 1; i <= k; i++) {
			string b[50];
			bool l = true;
			for (int j = 0; j < n; j++) {
				if (a[j].length() < i) b[j] = a[j];
				else b[j] = a[j].substr(0, i);
				for (int z = 0; z < j; z++) {
					if (b[z] == b[j]) {
						l = false;
						break;
					}
				}
			}
			if (l) {
				m = i;
				break;
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 3048
package main

import "fmt"

func main() {
	var n, s string
	fmt.Scan(&n)
	s = ""
	for _, c := range n {
		switch string(c) {
		case "9":
			s += "1"
		case "1":
			s += "9"
		}
	}
	fmt.Println(s)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		int n = s.length();
		boolean eq = s.charAt(0) == s.charAt(n - 1);
		if (eq) {
			System.out.println(n % 2 == 0 ? "First" : "Second");
		} else {
			System.out.println(n % 2 == 1 ? "First" : "Second");
		}
	}
}


Measured memory_bytes: 26788
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,c;
  cin>>a;
  int b[a];
  for(int i=0;i<a;i++){
  cin>>b[i];
  }
  sort(b,b+a);
  c=a/2;
  cout<<b[c]-b[c-1]<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;


int main(void) {
  ll w,h,x,y;
  cin >> w >> h >> x >> y;
  
  
  
  long double p;
  long double q = 0.5;
  if(w%2==0 || h%2==0)p = (w*h)/2;
  else {
    p = w*h/2 + q;
    
    
  }
  
   
  cout << fixed<< setprecision(10)  <<  p << endl;
  if(w%2==0 && h%2==0 && x == w/2 && y == h/2) cout << 1 << endl;
  else cout << 0 << endl;

  
}


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

int main() {
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)){
    cout<<"Bad"<<endl;
  }
  else if(s.at(1)==s.at(2)){
    cout<<"Bad"<<endl;
  }
  else if(s.at(2)==s.at(3)){
    cout<<"Bad"<<endl;
  }
  else{
    cout<<"Good"<<endl;
  }
  
}


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

int main() {
  string s;
  cin>>s;
  string ans;
  if (s=="Sunny") ans="Cloudy";
  else if (s=="Cloudy") ans="Rainy";
  else ans="Sunny";
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

int N, K;
int R, S, P;
string T;

int getHandPoint(char hand)
{
    if (hand == 'r')
        return P;
    else if (hand == 's')
        return R;
    else if (hand == 'p')
        return S;
    else
        return -999;
}

int main(void)
{
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    vector<char> lastHand(K, 'x');
    int max_score = 0;

    for (int i = 0; i < N; i++)
    {
        if (T[i] != lastHand[i % K]) {
            max_score += getHandPoint(T[i]);
            lastHand[i % K] = T[i];
        }
        else lastHand[i % K] = 'x';
    }

    cout << max_score << '\n';

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 1e7+10;
LL sum[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j+=i){
			sum[j]+=1;
		}
	}
	LL ans=0;
	for(int i=1;i<=n;i++){
		ans+=i*sum[i];
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int long long a,b,ans=0;
  cin>>a>>b;
  int long long cou=1;
  for(int i=0;cou<b;i++){
    cou--;
    cou+=a;
    ans++;
  }
  cout<<ans;
}


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

using namespace std;

typedef long long ll;

int main(){
 ll N; cin >> N; 
  map<ll,ll> mp;
  for(auto a: mp){
    ll s = a.first;
    mp[s] = 0;}

    
  for(ll i = 0; i  < N; i++){
    ll d; cin >> d; mp[d]++;}
  
  ll M; cin >> M;
  
  for(ll i = 0; i < M; i++){
    ll t ; cin >> t;
    if(mp[t] == 0){ cout << "NO" << endl; return 0;}
    mp[t]--; }
  cout << "YES" << endl; return 0;}
  

Measured memory_bytes: 12800
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		int a;
		cin >> a;
		if(a%2 == 1) continue;
		if(a%3 == 0) continue;
		if(a%5 == 0) continue;
		cout << "DENIED" << endl;
		return 0;
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        long res = 0;
        for (int i = 1; i < n; i++) {
            res += (n - 1) / i;
        }
        System.out.println(res);
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32688
N,M,X=map(int,input().split())
CA=[list(map(int,input().split())) for i in range(N)]
kotae=[]
def saiki(A):
    if len(A)==N:
        goukei=[0]*M
        onedan=0
        for i in range(N):
            if A[i]==1:
                for j in range(M):
                    goukei[j]+=CA[i][j+1]
                onedan+=CA[i][0]
        #print(goukei)
        if min(goukei)>=X:
            kotae.append(onedan)
        return
    for i in range(2):
        A.append(i)
        saiki(A)
        A.pop()
saiki([])
if len(kotae)==0:
    print(-1)
    exit()
print(min(kotae))

Measured memory_bytes: 9220
from math import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def div3(a,b):
    c1=(2*a+b)/3
    c2=(a+2*b)/3
    return [c1,c2]

def main():
    n=int(input())
    xy=[[0,0],[100,0]]
    #aa=list(map(int, input().split()))
    for _ in range(n):
        nxy=[[0,0]]
        for [x0,y0],[x4,y4] in zip(xy,xy[1:]):
            x1,x3=div3(x0,x4)
            y1,y3=div3(y0,y4)
            a=((x3-x1)**2+(y3-y1)**2)**0.5
            rad=atan2(y3-y1,x3-x1)
            x2=x1+a*cos(rad+pi/3)
            y2=y1+a*sin(rad+pi/3)
            nxy+=[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
        xy=nxy
    for x,y in xy:
        print(x,y)

main()



Measured memory_bytes: 6504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

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

    int n, q;
    cin >> n >> q;

    UnionFind uf(n);

    while (q--) {
        int t, u, v;
        cin >> t >> u >> v;

        if (t == 0) {
            uf.unite(u, v);
        } else {
            cout << uf.same(u, v) << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,inf=1e9+10,mod=1e9+7;
int a[M],n;
int ans[M];
bool mark[M];
int pnt=1;
main()
{
	int now=0;
	cin>>n;
	int tmp=0;
	if(n==3)return cout<<"2 5 63",0;
	for(int i=1;true;i++)
	{	
		if(i%2==0 || i%3==0)
		{
			ans[pnt++]=i;
			mark[i]=1;
			tmp+=i;
		}
		if(pnt==n-1)break;
	}		
	if(tmp%3!=0)
	{
		int hlp=3-tmp%3;
		for(int j=2;true;j+=2)
		{
			if(!mark[j] && j%3==hlp)
			{
				ans[pnt++]=j;
				mark[j]=1;
				break;
			}
		}
	}
	if(tmp%2==1)
	{
		for(int j=3;true;j+=6)
		{
			if(!mark[j]){
				ans[pnt++]=j;
				mark[j]=1;
				break;
			}
		}
	}
	for(int j=6;true;j+=6)
	{
		if(pnt==n+1)break;
		if(!mark[j])
		{
			ans[pnt++]=j;
		}
	}
	for(int i=1;i<pnt;i++)
	{
		cout<<ans[i]<<" ";
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
struct UF {
    int N;
    vector<int> par; // 親ノード rootで取得すること
    vector<int> rank;

    UF(int n) : N(n), par(N), rank(N,0) {
        rep(i,N) {par[i] = i;}
    }

    int root(int x) { //ノードの根を返す
        if (par[x] == x) return x; //親が自分なら自分を返す
        else {
            int r = root(par[x]); //根まで遡りながら経路圧縮
            return par[x] = r;
        }
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x; //ランクの小さい方に接続
        return true;
    }
    int treenum() { //merge成功回数でも求まる
        int num=0;
        rep(i,N){
            num += root(i)==i;
        }
        return num;
    }
};

//--MAIN-----------------------------------
void Main() {
    ll N,M,K; cin>>N>>M>>K;
    UF uf(N);
    vector<ll> A(N);
    vector<ll> ans(N,0);
    rep(i,M){
        ll a,b; cin>>a>>b; --a,--b;
        uf.merge(a,b);
        --ans[a];
        --ans[b];
    }
    map<ll,ll> rtct;
    rep(i,N){
        ++rtct[uf.root(i)];
    }
    rep(i,N){
        ans[i]+=rtct[uf.root(i)];
    }
    rep(i,K){
        ll c,d; cin>>c>>d; --c,--d;
        if(uf.issame(c,d)){
            --ans[c];
            --ans[d];
        }
    }
    rep(i,N){
        cout<< ans[i]-1 <<" ";
    }
    cout<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 8960
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias route = Tuple!(long, "From", long, "To");
long bignum = 1_000_000_007;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, x;
    scan(n, x);
    auto a = aryread();
    a.sort();
    long count;
    foreach (i, e; a)
    {
        if(x < e && i < n)
            break;
        
        x -= e;
        count++;
    }

    if(x > 0 && count > n - 1)
        count--;
    
    count.writeln();
}

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

int main(){
    int n,a,b;
    while(cin >> n >> a >> b){
        int ans = 0;
        rep(i,n){
            int x;
            cin >> x;
            if(!(a <= x && x < b)) ++ans;
        }
        cout << ans << endl;
    }
    
}


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

const int N = 1e5 + 5;

int n, m;
int indeg[N], vis[N];
int len[N];
vector<int> G[N];
vector<int> P[N];

vector<int> t;

void dfs(int u) {
  vis[u] = 1;
  for (int v : G[u]) {
    if (!vis[v])
      dfs(v);
  }
  t.push_back(u);
}

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    P[b].push_back(a);
    indeg[b]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      dfs(i);
  }
  reverse(t.begin(), t.end());
  for (int v : t) {
    for (int u : P[v]) {
      len[v] = max(len[u] + 1, len[v]);
    }
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(len[i], mx);
  }
  cout << mx << '\n';
  return 0;
}

Measured memory_bytes: 14972
#include <cstdio>
using namespace std;
const int maxn=200001;

int pos[maxn];
int num[maxn];
int a[maxn];
int n,m,ans,old,new_,p;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		num[a[i]]++;
	}
	
	for(int i=1;i<=n;i++) pos[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i-num[i]+1;j<=i;j++)
		    pos[j]++;
	}
	
	for(int i=1;i<=n;i++) if (!pos[i]) ans++;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&p,&new_);
		old=a[p];
		a[p]=new_;
		
		if (old-num[old]+1>=1)
		{
			pos[old-num[old]+1]--;
			if (!pos[old-num[old]+1]) ans++;
		}
		num[old]--;
		if (new_-num[new_]>=1)
		{
			pos[new_-num[new_]]++;
			if (pos[new_-num[new_]]==1) ans--;
		}
		num[new_]++;
		
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
# include <bits/stdc++.h>
# define rr register
# define int long long
const int N=100010,INF=0x3f3f3f3f;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
signed main(void){
	int H,W;
	H=read(),W=read();
	int ans=H*W/2;
	if(H*W%2){
		++ans;
	}
	if(H==1||W==1){
		printf("1");
		return 0;
	}
	printf("%lld",ans);
	return 0;
}


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


int main() {
	std::string str;
	std::cin >> str;
	std::sort(std::begin(str), std::end(str));

	bool beauty{ true };
	for (auto it = std::begin(str); it != std::end(str); ++it) {
		auto num = std::count(it, std::end(str), *it);
		if (num % 2 != 0) beauty = false;
		if (num > 0) it+=num-1 ;
	}

	auto res = beauty ? "Yes" : "No";
	std::cout<<res<< "\n";
}

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

int main() {
    int l, r;
    cin >> l >> r;
    const int MOD = 2019;
    if (MOD <= r-l+1) {
        cout << 0 << endl;
        return 0;
    }

    l %= MOD;
    r %= MOD;

    if (r < l) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1e9;
    for (int i = l; i <= r-1; ++i) {
        for (int j = l+1; j <= r; ++j) {
            int p = (i * j) % MOD;
            ans = min(ans, p);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        // a[i]=abs(a[i]-(i+1));
        a[i]=(a[i]-(i+1));
    }

    SORT(a);
    ll ans = 0;
    REP(i, n/2){
        ans += abs(a[a.size()-i-1]-a[i]);
    }
    pr(ans);
}

Measured memory_bytes: 1024
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
sum_v = 0
for i in range(N):
    w[i], v[i] = map(int, input().split())
    sum_v += v[i]

DP = [0] * (sum_v+1)

for i in range(N):
    for j in (reversed(range(sum_v))):
        if j == 0 or DP[j] != 0:
            if DP[j + v[i]] > DP[j] + w[i] or DP[j + v[i]] == 0:
                DP[j + v[i]] = DP[j] + w[i]
                

for j in (reversed(range(sum_v+1))):
    if DP[j] != 0 and DP[j] <= W:
        print(j)
        break

Measured memory_bytes: 42076
def main():
    K, N = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))

    dist = [K + A[0] - A[-1]] + [A[i + 1] - A[i] for i in range(N - 1)]
    # print(dist)

    print(sum(dist) - max(dist))


if __name__ == '__main__':
    main()


Measured memory_bytes: 26676
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}

//ifstream f(".in");
//ofstream g(".out");

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif

  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }

  int ans = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int x = 0, y = 0;
    for (int bit = 0; (1 << bit) <= mask; ++bit) {
      if (mask & (1 << bit)) {
        x += v[bit];
        y += c[bit];
      }
    }
    ans = max(ans, x - y);
  }
  cout << ans << '\n';

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 256
n=int(input())
lst=[int(i) for i in input().split()]
cnt=0
for i in range(n-2):
    if lst[i+1]!=min(lst[i],lst[i+1],lst[i+2]) and lst[i+1]!=max(lst[i],lst[i+1],lst[i+2]):
        cnt+=1
print(cnt)        

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#define For(i,A,B) for(i=(A);i<=(B);++i)
using namespace std;
typedef long long ll;
const int N=200050;
struct node{
    int a,b;
}a[N];
int b[N],f[35];
ll s[N];
inline bool cmp(const node &a,const node &b){return (ll)a.a*(b.b+1)>(ll)b.a*(a.b+1);}
inline void chkmin(int &a,int b){if(b<a)a=b;}
inline void chkmax(int &a,int b){if(b>a)a=b;}
int main(){
    int n,t,n1=0,n2=0,i,j,k=0,x,y,ans=0;
    ll tp;
    scanf("%d%d",&n,&t);
    For(i,1,n){
        scanf("%d%d",&x,&y);
        if(x){a[++n1].a=x;a[n1].b=y;}
        else b[++n2]=y;
    }
    sort(a+1,a+n1+1,cmp);
    sort(b+1,b+n2+1);
    For(i,1,n2)s[i]=s[i-1]+b[i]+1ll;
    memset(f,0x3f,sizeof(f));
    f[0]=0;
    For(i,1,n1){
        for(j=k;j>=0;--j)if((tp=(ll)(a[i].a+1)*(f[j]+1)+a[i].b)<=(ll)t)chkmin(f[j+1],tp);
        if(f[k+1]<=t)++k;
    }
    For(i,0,k)chkmax(ans,i+upper_bound(s+1,s+n2+1,t-f[i])-s-1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] grid = new int[w][h];
		int wCount = 0;
		for (int i = 0; i < h; i++) {
			String s = sc.next();
			for (int j = 0; j < w; j++) {
				if (s.charAt(j) == '.') {
					grid[j][i] = -1;
					wCount++;
				} else {
					grid[j][i] = Integer.MIN_VALUE;
				}
			}
		}
		grid[0][0] = 0;
		for (int i = 0; i < wCount; i++) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < h; k++) {
					if (grid[j][k] == i) {
						if (j != 0) {
							if (grid[j - 1][k] == -1) {
								grid[j - 1][k] = i + 1;
							}
						}
						if (j != w - 1) {
							if (grid[j + 1][k] == -1) {
								grid[j + 1][k] = i + 1;
							}
						}
						if (k != 0) {
							if (grid[j][k - 1] == -1) {
								grid[j][k - 1] = i + 1;
							}
						} 
						if (k != h - 1) {
							if (grid[j][k + 1] == -1) {
								grid[j][k + 1] = i + 1;
							}
						}
					}
				}
			}
			if (grid[w - 1][h - 1] != -1) {
				System.out.println(wCount - grid[w - 1][h - 1] - 1);
				return;
			}
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b * 2) {
		cout << a - b - b << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int x[3];

  for(int i = 0;i < 3;i++){
    scanf("%d",&x[i]);
  }

  if(x[0]*x[1]*x[2] == 175){
    printf("YES");
  }else{
    printf("NO");
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a, b;
	int d, r;
	double f;

	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)(a) / b ;

	printf("%d %d %f\n", d, r, f);
	
	return 0;
}


Measured memory_bytes: 2112
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, w int
	fmt.Scan(&n, &w)

	var ws, vs []int
	for i := 0; i < n; i++ {
		var ww, vv int
		fmt.Scan(&ww, &vv)
		ws = append(ws, ww)
		vs = append(vs, vv)
	}

	sumV := 0
	for _, v := range vs {
		sumV += v
	}

	dp := make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, sumV+1)
		for j := 0; j < sumV+1; j++ {
			dp[i][j] = math.MaxInt32
		}
	}
	// dp[i][j]: i番目までで価値jを実現するための最小重さ

	dp[0][0] = 0
	dp[0][vs[0]] = ws[0]

	for i := 1; i < n; i++ {
		for j := 0; j < sumV+1; j++ {
			if j - vs[i] >= 0 {
				dp[i][j] = int(math.Min(float64(dp[i-1][j]), float64(ws[i] + dp[i-1][j-vs[i]])))
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}

	maxV := 0
	for j, ww := range dp[n-1] {
		if ww <= w {
			maxV = j
		}
	}

	fmt.Println(maxV)
}

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

int main(void){
    int n; cin >>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    sort(a.begin(),a.end());
    ll target=a[0],cnt=0,ans=0;
    for(int i=0;i<n;i++){
        if(a[i]!=target || i==n-1){
            if(i==n-1) cnt++;
            if(cnt<target) ans += cnt;
            else if(target < cnt) ans += cnt-target;
            cnt=1;target=a[i];
        }else{
            cnt++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int a,b;
   cin>>a>>b;
   
   cout << max(0, a-b*2) << endl;
   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    bool ok = 0;
    string s; cin >> s;
    for(int i = 0; i < s.size() - 1; ++i){
        if(s[i] == s[i + 1]){
            ok = 1;
        }
    }
    puts(ok ? "Bad" : "Good");
    return 0;
}

Measured memory_bytes: 3648
//参考：https://blog.csdn.net/HQG_AC/article/details/85984085 
//记忆化优点：https://blog.csdn.net/u011639256/article/details/29389951
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
 
int n,k;
int a[maxn],dp[100005][2];//dp[容量][人]记录是否能赢 
//记忆化搜索初始化必须可以实现判断是否记忆
//记忆化好处：从上往下递归，但是不用吧中途的所有情况都记下来，只需要用到递归到的状态的值 

bool dfs(int x,int y){
	if(dp[x][y]>=0)return dp[x][y];
	int ans=0;
	for(int i=1;i<=n;i++){
		if(x>=a[i])
		ans|=!dfs(x-a[i],!y);//只要后面状态有一个是另一方必输则当前状态此人必赢，公式很妙 
	} 
	return dp[x][y]=ans;
}

signed main()
{
	memset(dp,-1,sizeof dp);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	if(dfs(k,0))cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
} 

Measured memory_bytes: 9040
def main():

    N, A, B = map(int, input().split())
    H = []
    for _ in range(N):
        H.append(int(input()))

    l, r = 0, max(H) // B + 1
    while l < r:
        m = (l + r) // 2
        if isvalid(m, H, N, A, B):
            r = m
        else:
            l = m + 1

    return r

def isvalid(n, H, N, A, B):
    alive = []
    for i in range(len(H)):
        if H[i] - n*B > 0:
            alive.append(H[i]-n*B)
    count = 0
    for v in alive:
        if v % (A-B) == 0:
            count += v //(A-B)
        else:
            count += v //(A-B) + 1
    if count <= n:
        return True
    else:
        return False



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    while(1){
        ll n;cin>>n;
        if(n==0)break;
        ll sum=0;
        rep(i,n/4){
            ll a;cin>>a;
            sum+=a;
        }
        cout<<sum<<endl;
    }
}


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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a, b, x; cin >> a >> b >> x;

  if (x < a) cout << "NO\n";
  else if (x <= a + b) cout << "YES\n";
  else cout << "NO\n";
  
  return (0);
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, K;
ll h[200000];
vector<ll> dp(200000, 1e10);

signed main() {
  cin >> N >> K;
  rep(i, N)
    cin >> h[i];
  dp[0] = 0;
  rep(i, N) {
    for (ll j=i+1; j<=i+K; j++) {
      if (j<N) chmin(dp[j], dp[i] + abs(h[i]-h[j]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 2560
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = [IL() for i in range(2)]
dp = [[0]*N for i in range(2)]

dp[0][0] = A[0][0]
for i in range(1,N):
	dp[0][i] = dp[0][i-1] + A[0][i]

dp[1][0] = A[0][0] + A[1][0]
for i in range(1,N):
	dp[1][i] = max(dp[0][i],dp[1][i-1]) + A[1][i]

print(dp[1][-1])

Measured memory_bytes: 12480
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

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

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

int main() {
  for (int i = 0; i < 4; i++) {
    int t, n; cin >> t >> n;
    if (t == 1) cout << 6000 * n << endl;
    if (t == 2) cout << 4000 * n << endl;
    if (t == 3) cout << 3000 * n << endl;
    if (t == 4) cout << 2000 * n << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (100000)

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (as[i] % 2 == 1) {
      ans = 1;
    }
  }
  if (ans) {
    printf("first\n");
  } else {
    printf("second\n");
  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < k; i++) {
    vector<int> b(n + 1);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n, j + a[j] + 1);
      b[l]++;
      b[r]--;
    }
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
    }
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;;
  }
  return 0;
}

Measured memory_bytes: 4820
n, a, b, c = map(int, input().split())
d = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
queries = [d[input()] for _ in range(n)]
history = []
abc = [a, b, c]
for i in range(n):
    x, y = queries[i]
    if abc[x] == 0 and abc[y] == 0:
        print('No')
        exit()
    if abc[x] == 1 and abc[y] == 1:
        if i == n - 1:
            history.append('ABC'[x])
            abc[x] += 1
            abc[y] -= 1
        elif x in queries[i + 1]:
            history.append('ABC'[x])
            abc[x] += 1
            abc[y] -= 1
        else:
            history.append('ABC'[y])
            abc[x] -= 1
            abc[y] += 1
    else:
        if abc[x] > abc[y]:
            history.append('ABC'[y])
            abc[x] -= 1
            abc[y] += 1
        else:
            history.append('ABC'[x])
            abc[x] += 1
            abc[y] -= 1
print('Yes')
print('\n'.join(history))


Measured memory_bytes: 82904
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    vector<string> words = {
        "dream",
        "dreamer",
        "erase",
        "eraser"
    };
    auto can_remove = [](string& s, string& w) {
        bool ans = true;
        for(int i = 1; i <= w.size() and ans; i++) {
            ans &= s.size() - i >= 0 and s[s.size() - i] == w[w.size() - i];
        }
        return ans;
    };
    auto rem = [](string& s, int sz) {
        for(int i = 0; i < sz; i++) {
            s.pop_back();
        }
    };
    bool can = true;
    while(not s.empty() and can) {
        bool valid = false;
        for(string w : words) {
            if(can_remove(s, w)) {
                rem(s, w.size());
                valid = true;
            }
        }
        can &= valid;
    }
    cout << (can ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
N,M=map(int,input().split())

LM=0
RM=1000000

for i in range(M):
	L,R=map(int,input().split())

	if(L>=LM):
		LM=L

	if(RM>=R):
		RM=R

if (RM-LM<0):
	print(0)
else:
	print(RM-LM+1)


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

int main() {
int A,B,C,D,E,a,b,c,d,e,sum=0,div=10;
  vector<int> num(5);
  vector<int> sumnum(5);
   cin >> A >> B >> C >> D >> E;

   a = A % 10;
   b = B % 10;
   c = C % 10;
   d = D % 10;
   e = E % 10;
   num = {a,b,c,d,e};
   sumnum = {A,B,C,D,E};
  for(int i=0;i<5;i++){
   if(num[i] ==0){
    sum = sum +sumnum[i];
   }
   else{
     if( num[i] < div ){
      div = num[i];
          if( sumnum[i] > 10 ){ sum = sum + sumnum[i]-num[i]+10;
          }
          else if(num[i] < 10){
          sum = sum +10;
          }
     }
     else{
      sum = sum +sumnum[i] + 10 -num[i];
     }
   }

  }

 if(div ==10){
  sum = sum ;
 }
 else{

 sum = sum + div -10;
}
 cout << sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
	
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> c(H);
	for(int i=0; i<H; i++) cin >> c[i];

	ll ans = 0;
	//bit全探索
	for(int i=0; i< (1<< H); i++){
		vector<string> tmp = c;
		for(int j=0; j< H; j++){
			if( (i>>j) &1){
				for(int m=0; m<W; m++){
					tmp[j][m] = '+';
				}
			}

		}
		for(int s=0; s<(1<<W); s++){
			vector<string> tmp2 = tmp;
			for(int t=0; t<W; t++){
				if( (s>>t) &1){
					for(int u=0; u<H; u++){
						tmp2[u][t] = '+';
					}
				}
			}
			int num = 0;
			for(int x=0; x<H; x++){
				for(int y=0; y<W; y++){
					if(tmp2[x][y] == '#') num++;
				}
			}
			if(num == K) ans++;
			// cout << " tmp2: " << endl;
			// cout << tmp2[0][0] << endl;
			// cout << tmp2[1][1] << endl;
		}

	}
	
	cout << ans << endl;

}


Measured memory_bytes: 3600
n = int(input())
s = list(map(int, input().split()))
a = [0]*9
c = ""
mn = 400
mx = 399
for i in s:
    if 1 <= i <= mx:
        a[0] = 1
    elif mn <= i <= mx+mn:
        a[1] = 1
    elif mn*2 <= i <= mx+mn*2:
        a[2] = 1
    elif mn*3 <= i <= mx+mn*3:
        a[3] = 1
    elif mn*4 <= i <= mx+mn*4:
        a[4] = 1
    elif mn*5 <= i <= mx+mn*5:
        a[5] = 1
    elif mn*6 <= i <= mx+mn*6:
        a[6] = 1
    elif mn*7 <= i <= mx+mn*7:
        a[7] = 1
    elif  mn*8 <= i <= mn*12:
        a[8] += 1

if a[8] > 0:
    c = "".join(map(str,a))
    c = c.replace("0","")
    if len(c) == 1:
        print(1,sum(a))
    else:
        print(sum(a)-a[8],sum(a))
elif a[8] == 0:
    print(sum(a), sum(a))

Measured memory_bytes: 3064
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
typedef long long ll;
const ll MAX_N = 1e5+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][2];
int a[MAX_N];
string res[2] = {"Second" , "First" };
int n,k;

int main()
{
    cin >> n >> k;
    for(int i = 1;i<=n;++i)
        cin >> a[i];
    for(int i = 1;i<=k;++i)
    {
        for(int t = 0;t<2;++t)
        {
            for(int x = 1;x<=n;++x)
            {
                if (i-a[x]>=0)
                {
                    dp[i][t] |= (dp[i-a[x]][t^1])^1;
                }
            }
        }
    }
    cout << res[dp[k][0]];
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int main()
{
    int a, b, c, n, i, min, pre, cur;
 
    scanf("%d", &n);
 
    scanf("%d", &min);
    scanf("%d", &pre);
 
    a = pre - min;
    if (min > pre) min = pre;
 
    for (i = 2; i < n; i++)
    {
        scanf("%d", &cur);
        b = cur - pre;
        c = cur - min;
 
        if (b > c) { if (a < b) a = b; }
        else if (a < c) a = c;
 
        if (min > cur) min = cur;
 
        pre = cur;
    }
 
    printf("%d\n", a);
    return 0;
}

Measured memory_bytes: 1848
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    uint64_t i, n, d[100000];
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d, d+n);
    cout << d[(n/2)]-d[(n/2)-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
/*
 * 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;
  cin >> n;
  cout << n/3 << endl;
}


Measured memory_bytes: 256