akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	stdin = null;
		int		sum   = 0;

		while ((stdin = parseStdin()) != null) {
			// 半角英数字ピリオドの文字列を#に置き換えておく
			stdin = stdin.replaceAll("[^0-9]", " ").trim();
			stdin = stdin.replaceAll("[ ]+", " ");
			if (!stdin.isEmpty()) {
				for (String s : stdin.split(" ")) {
					// #が含まれる文字列は対象外
					sum += Integer.parseInt(s);
				}
			}
		}

		System.out.println(sum);
	}

	private static String parseStdin() {
		String	stdin = null;

		try {
			stdin = br.readLine();
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 18080
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	ret.pb(n);
	return ret;
}

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

	int cnt = 0;
	SORT(a, N);
	REP(i, N) {
		if (x >= a[i]) {
			if (i == N - 1) {
				if (x == a[i])cnt++;
				break;
			}
			cnt++;
			x -= a[i];
		}
		else {
			break;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,q;
ll x[500005],y[500005],z[500005];
ll dp[500005];
bool no[3005][3005];
char s[500005],t[500005];
bool flag,dame;

int main(){
    cin >> n >> k;
	for(i=0;i<k;i++){
		cin >> x[i] >> y[i];
	}
	dp[1] = 2;
	ll pos = 1;
	dp[2] = 1;
	for(i=0;i<k;i++){
		if(pos == x[i]){
			swap(dp[x[i]],dp[y[i]]);
			pos = y[i];
		}else if(pos == y[i]){
			swap(dp[x[i]],dp[y[i]]);
			pos = x[i];
		}else{
			swap(dp[x[i]],dp[y[i]]);
		}
		dp[pos - 1] = 1;
		dp[pos + 1] = 1;
	}
	for(i=1;i<=n;i++){
		if(dp[i] >= 1)ans++;
	}
	p(ans);

	return 0;
}

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



int main(){
    int N; cin >> N;
    string W[110];
    for(int i=0; i<N; i++){
        cin >> W[i];
    }

    bool flag=true;

    for(int i=1; i<N; i++){
        if( W[i-1].at(W[i-1].size()-1) != W[i].at(0) ) flag = false;
    }

    set<string> s;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(W[i]==W[j]) flag = false;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,i,ans=0;
    bool f=true;
    cin>>n;
    vector<int> v(n);
    for(i=0;i<n;i++){
        cin>>v[i];
    }
    while(f){
        f=false;
        for(i=0;i<n-1;i++){
            if(v[i]>v[i+1]){
                swap(v[i],v[i+1]);
                ans++;
                f=true;
            }
        }
    }
    for(i=0;i<v.size();i++){
        cout<<v[i]<<((i<v.size()-1)?' ':'\n');
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3088
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>n;
    cout<<24+(24-n)<<endl;

    return 0;
}


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


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    max_leaves = sum(A)
    if N == 0 and A[0] == 1:
        return 1
    if A[0] > 0:
        return -1
    ans = 1
    n_nodes = 1
    for i in range(1, N+1):
        n_nodes = min(n_nodes * 2, max_leaves)
        ans += n_nodes
        if i < N and A[i] > n_nodes - 1:
            return -1
        max_leaves -= A[i]
        n_nodes -= A[i]
    if n_nodes != 0:
        return -1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 20004
# coding: utf-8
# Your code here!
from sys import stdin
import numpy as np
#import math
#from functools import reduce
    
N, M = [int(x) for x in stdin.readline().rstrip().split()]
#N = int(input())
#S = list(input())

costs = []
num = []

for n in range(N):
    ai, bi = [int(x) for x in stdin.readline().rstrip().split()]
    costs += [ai]
    num += [bi]
    
sorted_idx = np.argsort(costs)
costs = list(np.array(costs)[sorted_idx])
num = list(np.array(num)[sorted_idx])

count_num = 0
count_cost = 0
for i, n in enumerate(num):
    if count_num + n < M:
        count_cost += n*costs[i]
        count_num += n
    else:
        count_cost += costs[i]*(M-count_num)
        break

print(count_cost)

Measured memory_bytes: 28404
#include <stdio.h>

int main(void)
{

    int a, n, i;
    long long  max = -1000000;
    long long  sum = 0;
    long long  min = 1000000;

    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        scanf("%d", &a);
        if (max < a)
            max = a;
        if (min > a)
            min = a;
        sum += a;
    }

    printf("%ld %ld %ld\n", min, max, sum);

    return 0;
}

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

int main(int argc, char const *argv[]) {
  int n;
  string s;
  int cnt = 0;
  cin >> n;
  cin >> s;

  for (size_t i = 0; i < n; i++) {
    if (s[i] == '.') cnt++;
  }
  int ans = cnt;

  for (size_t i = 0; i < n; i++) {
    if (s[i] == '.')
      cnt--;
    else if (s[i] == '#')
      cnt++;
    ans = min(ans, cnt);
  }

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

Measured memory_bytes: 1152
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
#input = sys.stdin.readline


def resolve():
    n, m = map(int, input().split())
    all_wa = 0
    all_ac = 0
    ac_list = []
    p_list, s_list = [], []
    first_ac_dic = {}

    wa_count_dic = {}
    wa_num = 0
    for i in range(m):
        p, s = input().split()
        p = int(p)
        p_list.append(p)
        s_list.append(s)

        if s == "AC":
            if p in first_ac_dic:
                pass
            else:
                first_ac_dic[p] = i
                wa_num += wa_count_dic.get(p, 0)
        else:
            wa_count_dic[p] = wa_count_dic.get(p, 0) + 1

    ans_ac = len(first_ac_dic)

    print(ans_ac, wa_num)


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 71512
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,x[100010];
vector<int> a[100010];
bool p;
inline L dfs(int i,int j)
{
    if(a[i].size()==1)
      return x[i];
    int k;
    L l=0,u=0,v;
    for(k=0;k<a[i].size();k++)
      if(a[i][k]!=j)
        {
         v=dfs(a[i][k],i);
         l+=v;
         u=max(u,v);
        }
    L w=l-x[i];
    if(w<0 || 2*w>l || w>l-u)
      {
       p=1;
       return 0;
      }
    else
      return l-2*w;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	if(n==2)
	  {
       if(x[1]==x[2])
         printf("YES\n");
       else
         printf("NO\n");
       return 0;
      }
	for(i=1;i<n;i++)
	  {
       scanf("%d%d",&j,&k);
       a[j].push_back(k);
       a[k].push_back(j);
      }
    for(i=1;i<=n;i++)
      if(a[i].size()>1)
        break;
    if(dfs(i,0) || p)
      printf("NO\n");
    else
      printf("YES\n");
	return 0;
}


Measured memory_bytes: 10752
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define sz(a) (int)(a.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin>>n>>k;
    vii vec(n);
    for0(i,n) cin>>vec[i].first>>vec[i].second;
    sort(all(vec));
    int sum = 0;
    for0(i,n) {
        sum += vec[i].second;
        if(sum >= k) {
            cout<<vec[i].first;
            return 0;
        }
    }

    return 0;
}      

Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			int M = sc.nextInt();
			int[] h = new int[H];
			int[] w = new int[W];
			Set<Integer> hset = new HashSet<>();
			Set<Integer> wset = new HashSet<>();
			Set<Point> pset = new HashSet<>();
			for (int i = 0; i < M; i++) {
				int tmph = sc.nextInt() - 1;
				int tmpw = sc.nextInt() - 1;
				h[tmph]++;
				w[tmpw]++;
				hset.add(tmph);
				wset.add(tmpw);
				pset.add(new Point(tmph, tmpw));
			}
			Set<Integer> hmax = new HashSet<>();
			Set<Integer> wmax = new HashSet<>();
			int maxh = 0;
			int maxw = 0;
			for (int hh : hset) {
				int tmp = h[hh];
				if (tmp > maxh) {
					hmax.clear();
					hmax.add(hh);
					maxh = tmp;
				} else if (tmp == maxh) {
					hmax.add(hh);
				}
			}
			hset.clear();
			for (int ww : wset) {
				int tmp = w[ww];
				if (tmp > maxw) {
					wmax.clear();
					wmax.add(ww);
					maxw = tmp;
				} else if (tmp == maxw) {
					wmax.add(ww);
				}
			}
			wset.clear();
			int cnt = 0;
			for (Point p : pset) {
				if (hmax.contains(p.h) && wmax.contains(p.w)) {
					cnt++;
				}
			}
			if (cnt == hmax.size() * wmax.size()) {
				System.out.println(maxh + maxw - 1);
			} else {
				System.out.println(maxh + maxw);
			}
		}
	}

	static class Point {
		int h;
		int w;

		public Point(int h, int w) {
			this.h = h;
			this.w = w;
		}
	}
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

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

int main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N,K;
   cin>>N>>K;
   ll MIN = INF;
   ll ans;
   for(int i=0;i<=N;i++){
      ans = 1;
      ans = pow(2,i);
      ans += K*(N-i);
      MIN = min(ans,MIN);
   }
   cout<<MIN<<endl;
   return 0; 
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;

vll counter;
vll ans;

void aaa(ll target, ll total_counter, Graph& tree, ll parent) {
  ll point = counter[target] + total_counter;
  ans[target] = point;
  REP(i, tree[target].size()) {
    if (tree[target][i] != parent) {
      aaa(tree[target][i], point, tree, target);
    }
  }
}

void Main() {
  ll n, q;
  cin >> n >> q;
  Graph tree(n);
  counter.assign(n, 0);
  ans.assign(n, 0);

  REP(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  REP(i, q) {
    ll p, x;
    cin >> p >> x;
    p--;
    counter[p] += x;
  }

  // COUTA(i, counter);

  aaa(0, 0, tree, -1);

  COUTA(i, ans);
}

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

/*
4 3
1 2
2 3
2 4
2 10
1 100
3 1
*/


Measured memory_bytes: 29800
//aea ctmr https://codeforces.com/contest/1271/submission/66946806
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
    
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 105000;
const int mod = 1e9 + 7;
using namespace std;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
 
vector <int> adj[N];
int alt1[N], alt2[N];
int x, y;

void dfs1(int u, int p){
    for(auto x1: adj[u]){
        if(x1 == p) continue;
        alt1[x1] = alt1[u] + 1;
        dfs1(x1, u);
    }
}
void dfs2(int u, int p){
    for(auto x1: adj[u]){
        if(x1 == p) continue;
        alt2[x1] = alt2[u] + 1;
        dfs2(x1, u);
    }
}

int main(){

    int n;
    cin >> n >> x >> y;

    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    alt1[x] = 0;
    alt2[y] = 0;
    dfs1(x, -1);
    dfs2(y, -1);
    int ans = 0;
    //trace(n);
    for(int i = 1; i <= n; i++){
        //trace(alt1[i]);
        if(alt1[i] < alt2[i]) ans = max(ans, alt2[i] - 1);
    }
    //trace(h, hm);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
#define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

// struct query{int l,int r}q[maxn];
// inline bool cmp(query a,query b) {return a.l!=b.l?a.l<b.l:a.r<b.r;}
int a[maxn],b[maxn];
signed main()
{
	ll n;
	fin>>n;
	for(rgi i=1;i<=n;++i) fin>>a[i]>>b[i];
	std::sort(a+1,a+1+n),std::sort(b+1,b+1+n);
	if(n&1) fout<<(b[n/2+1]-a[n/2+1]+1);
	else fout<<(b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1);
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 6720
#include <stdio.h>

int main (void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	if(c==1){
		printf("Open\n");
	}else if(a==1&&b==1){
		printf("Open\n");
	}else{
		printf("Close\n");
	}
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1012
n = int(input())
x = list(map(int,input().split()))
a = sum(x)//n
a1 = int(a) + 1
b = 0
c = 0
for i in range(n):
  b += (int(x[i]) - int(a))**2
  c += (int(x[i]) - int(a1))**2
print(min(b,c))

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

int main() {
	long long int a,b;
	cin >> a >> b;
	long long int c[a];
	long long int ns = 0;
	for (long long int i = 0;i < a;i++) {
		cin >> c[i];
		ns += c[i];
	}
	sort(c,c+a);
	long long int ans = 0;
	long long int sum = 0;
	if (ns < b) {
		ans = a - 1;
	} else {
		for (long long int i = 0;i < a;i++) {
			if (sum+c[i] <= b) {
				ans++;
				sum += c[i];
			}
			else {break;}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &i : v) os << i << ' ';
    return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    string s;
    cin >> s;
    if (s.back() == 's') s += "es";
    else
        s += "s";
    co(s);

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k, x=0;
  cin >> n >> k;
  vector <int>vec(n);
  for(int i=0;i<n;i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  for(int i=0;i<k;i++) x+=vec.at(i);
  cout << x << endl;

}


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

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

string s;

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif

	cin >> s;
	int len = int(s.size());
	string ans = string(len, 'x');
	cout << ans << '\n';

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int y, m, d;
  y = stoi(s.substr(0,4));
  m = stoi(s.substr(5,2));
  d = stoi(s.substr(8,2));
  if(y <= 2019 && m <= 4){
    if(m == 4 && d > 30){
      cout <<"TBD\n";
      return 0;
    }
    cout <<"Heisei\n";
    return 0;
  }
  cout <<"TBD\n";
  return 0;
}



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

int main() {
  string c;
  cin >> c;
	if(c == "a" || c== "e" ||c== "i" ||c== "o" ||c== "u") {
		cout << "vowel" << endl;
	}
	else{
		cout << "consonant" << endl;
	}

}


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

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> dat(n);
    rep(i, n)
    {
        cin >> dat[i];
    }
    //0以上の最小のインデックスを取得する
    ll index = lower_bound(dat.begin(), dat.end(), 3) - dat.begin();
    //このインデックスの値から初めてk個目まで行ったのが一番左端 index+k-1
    //このインデックスの値-1が右端になるときが一番右端 index-k
    ll count = 0;
    priority_queue<ll, vector<ll>, greater<ll>> o;
    for (ll i = min(n - 1, index + k - 1); i >= max(index - 1, k - 1); i--) //iは右端indexを表している。
    {
        //このとき右端がiより左端はi-k+1
        count = dat[i] - dat[i - k + 1] + min(abs(dat[i - k + 1]), abs(dat[i]));
        o.push(count);
    }
    cout << o.top();
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

using ll = long long;
const int mod = 1e9 + 7;

int main()
{
	fast();
	int n;
	int a, b, c;
	cin >> a>> b>>c;
	swap(a, b);
	swap(a, c);
	cout << a <<" "<< b<<" "<<c;
}			

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

shousuu = (n / 1.08) // 1
sita = int(shousuu - 2)
ue = int(shousuu + 2)

for i in range(sita, ue+1):
    if (i * 1.08) // 1 == n:
        print(i)
        exit()

print(':(')

Measured memory_bytes: 2940
/* written by : vipin kumar */
#include<iostream>
using namespace std;
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#define int long long int
#define mod 1000000007
int value[10000001]={0};
int prime[10000001]={0};
int sieve(int n)
{
	int j;
	for(j=1;j<=n;j++)
	{
		prime[j]=j;
		value[j]=1;
	}
	for(j=2;j<=n;j++)
	{
		if(prime[j]==j)
		{
			int i;
			for(i=1;i*j<=n;i++)
			{
				prime[i*j]=j;
				int x=i*j;
				int count=0;
				while(x%j==0)
				{
					count++;
					x/=j;
				}
				value[i*j]*=(count+1);
			}
		}
	}
	int answer=0;
	for(j=1;j<=n;j++)
	{
		answer+=(j*value[j]);
	}
	return answer;
}
int32_t main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     int n;
     cin>>n;
     int answer=sieve(n);
     cout<<answer<<endl;
}


Measured memory_bytes: 159852
def factorization(n):
    L=[]
    temp=n
    print(n,end="")
    print(":",end="")
    for i in range(2, int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i, c])
            for j in range(c):
                print("",i,end="")
    if temp!=1:
        print("",temp,end='')
    if L==[]:
        pass
    print()
    return L
n=int(input()) 
factorization(n)


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

vector<bool> IsPrime;

void sieve(ll max){
    if(max+1 > IsPrime.size()){  
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(ll i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(ll j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;     
}

int main() {
    ll n;
    cin >> n;

    sieve(1000000);

    ll ans = 0;
    for(int i = n;i < 1000000;i++){
        if(IsPrime[i]){
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll H, W;
    ll CH, CW;
    ll DH, DW;
    scanf("%lld", &H);
    scanf("%lld", &W);
    scanf("%lld", &CH);
    scanf("%lld", &CW);
    scanf("%lld", &DH);
    scanf("%lld", &DW);
    CH--;
    CW--;
    DH--;
    DW--;

    vector<vector<bool>> mazemap(H, vector<bool>(W));
    char c;
    scanf("%c", &c);
    for (ll i = 0; i < H; i++)
    {
        char c;
        for (ll j = 0; j < W; j++)
        {
            scanf("%c", &c);
            mazemap[i][j] = (c == '.');
        }
        scanf("%c", &c);
    }

    ll ans = 127;
    if (!mazemap[CH][CW])
    {
        ans = -1;
        printf("%lld\n", ans);
        return 0;
    }

    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> nexts;
    nexts.push({0, {CH, CW}});
    vector<vector<ll>> depthmap(H, vector<ll>(W, __LONG_LONG_MAX__));
    while (!nexts.empty())
    {
        auto current = nexts.top();
        nexts.pop();
        for (ll l = -2; l < 3; l++)
        {
            for (ll m = -2; m < 3; m++)
            {
                pair<ll, ll> currentpos = current.second;
                currentpos.first += l;
                currentpos.second += m;
                ll depth = current.first;
                if (currentpos.first < 0 || currentpos.second < 0 || currentpos.first >= H || currentpos.second >= W)
                    continue;

                if (!mazemap[currentpos.first][currentpos.second])
                    continue;

                if (!(abs(l) <= 1 && abs(m) <= 1 && abs(l) != abs(m)))
                    depth++;

                if (depthmap[currentpos.first][currentpos.second] > depth)
                {
                    depthmap[currentpos.first][currentpos.second] = depth;
                    nexts.push({depth, {currentpos.first, currentpos.second}});
                }
            }
        }
    }

    ans = depthmap[DH][DW];
    if (ans == __LONG_LONG_MAX__)
        ans = -1;
    printf("%lld\n", ans);
}


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

int main() {
  string str;
  int m, h;

  while (1) {
    cin >> str >> m;
    if (str == "-") break;
    for (int i = 0; i < m; i++) {
      cin >> h;
      str = str.substr(h) + str.substr(0, h);
    }
    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;


public class Contest
{
	public static void Main()
	{
		int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));

//		int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] d = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));

		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) {
			e[i] = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
			e[i] = e[i].Concat(new int[] { i }).ToArray();
		}

		Array.Sort(e,(x,y)=>(x[0]-y[0]));

		string h = "TLE";
		for(int i=0; i<n; i++){
			if(e[i][1]<=a[1]) {
				h = e[i][0].ToString();
				break;
			}
		}

		string ans = h.ToString();

		Console.WriteLine(ans);
	}
	
	private static int calc_main(int[] a,int[] b,int[] c,int[] d) {



		return 0;
	}




}


Measured memory_bytes: 13396
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1 << 28;
 
int main()
{
  int s, d, m;
  vector< int > w[100], p[100];
  int dp[301];
 
  while(cin >> s >> d >> m){
    for(int i = 0; i < s; i++){
      int k;
      cin >> k;
      w[i].resize(k), p[i].resize(k);
      for(int j = 0 ; j < k; j++){
        cin >> w[i][j] >> p[i][j];
      }
    }
    fill_n( dp, m + 1, 0);
    for(int i = 0 ; i < d ; i++ ){
      int f;
      cin >> f;
      for(int j = 0 ; j < w[f].size(); j++){
        for(int k = m ; k - p[f][j] >= 0; k--){
          dp[k] = max( dp[k], dp[k - p[f][j]] + w[f][j]);
        }
      }
    }
 
    int pos = 0;
    for(int i = 0 ; i <= m ; i++ ){
      if( dp[i] > dp[pos] ) pos = i;
    }
    cout << dp[pos] << " " << pos << endl;
  }
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200010];
ll vis[200010];
int main(){
	ll n,ANS=0;
	cin>>n;
	std::vector<ll> v(n);
	for(ll i=0;i<n;i++) cin>>v[i],a[v[i]]++;
	for(ll i=0;i<n;i++){
		if(vis[v[i]]!=1) {
			ANS+=(a[v[i]]*(a[v[i]]-1))/2;
			vis[v[i]]=1;
		}
	}
	for(ll i=0;i<n;i++){
		ll ans=ANS;
		ans-=(a[v[i]]*(a[v[i]]-1))/2;
		ans+=((a[v[i]]-1)*(a[v[i]]-2))/2;
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

long long Diff(long H, long W)
{
	long long Smax, Smin, Diff =0;

	long  H1 = (long) (H / 3.0);
	long  H2 = (long)((H - H1) / 2.0);
	Diff = (H1 == 0 || H2 == 0 ? pow(10,10) :  W*(H - H2 - 2 * H1));

	
	H1 = (long)(H / 2.0);
	H2 = H - H1;
	long W1 = (long)(2*W/ 3.0);
	Smax = max(H2*W1, H*(W- W1));
	Smin = min(H1*W1, H*(W - W1));
	H1 == 0 || W1 == 0 ?   Diff=Diff :	Diff = min(Diff, Smax - Smin);

	Smax = max(H2*(W1+1), H*(W - W1-1));
	Smin = min(H1*(W1+1), H*(W - W1-1));
	H1 == 0 || W1+1 == W ? Diff = Diff : Diff = min(Diff, Smax - Smin);


	return Diff;
}
int main()
{
	int H, W;
	cin >> H >> W;
	cout << min(Diff(H, W), Diff(W, H));
	cin >> H;
	return 0;
}



Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    T = [int(t) for t in input().split()]
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9
    Ans = 1
    H = [-1] * N
    H[0] = T[0]
    for i in range(1, N):
        if T[i] > T[i-1]: H[i] = T[i]
    if H[N-1] > -1 and H[N-1] != A[N-1]: Ans = 0
    else: H[N-1] = A[N-1]
    for i in reversed(range(N-1)):
        if A[i] > A[i+1]:
            if H[i] > -1 and H[i] != A[i]: Ans = 0
            elif T[i] < A[i]: Ans = 0
            else: H[i] = A[i]
        else:
            if H[i] == -1: 
                Ans *= min(T[i], A[i])
                Ans %= mod
    print(Ans)
            
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 18624
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	string S, T;
	int ans = 0;

	cin >> S >> T;

	for (int i = 0; i < 3; i ++) {
		if (S[i] == T[i]) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

if N==K: #全部
    ans=1
    for i in range(N):
        ans*=A[i]
        ans%=mod
    print(ans)
    exit()
if max(A)<0 and K%2==1: #答えがマイナス
    A.sort(reverse=True)
    ans=1
    for i in range(K):
        ans*=A[i]
        ans%=mod
    print(ans)
    exit()

plus=[]
minus=[]
for i in range(N):
    if A[i]>=0:
        plus.append(A[i])
    else:
        minus.append(A[i])
plus.sort(reverse=True) #5,3,1
minus.sort() #-5,-3,-1
plus_k=0
minus_k=0
if K%2==0:
    ans=1
else:
    ans=plus[0]
    plus_k=1

for _ in range(K):
    if plus_k+minus_k==K:
        break
    if plus_k>=len(plus)-1:
        ans*=minus[minus_k]*minus[minus_k+1]%mod
        ans%=mod
        minus_k+=2
        continue
    if minus_k>=len(minus)-1:
        ans*=plus[plus_k]*plus[plus_k+1]%mod
        ans%=mod
        plus_k+=2
        continue
    if plus[plus_k]*plus[plus_k+1]>minus[minus_k]*minus[minus_k+1]:
        ans*=plus[plus_k]*plus[plus_k+1]%mod
        ans%=mod
        plus_k+=2
        continue
    else:
        ans*=minus[minus_k]*minus[minus_k+1]%mod
        ans%=mod
        minus_k+=2
        continue
print(ans)


Measured memory_bytes: 31772
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
#include <vector>
#include<bitset>
#include<map>
using namespace std;

int main() {
	int l, r, d; cin >> l >> r >> d;
	if (l % d == 0)cout << r / d - l / d + 1 << endl;
	else cout << r / d - l / d << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll arra[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>arra[i];

    }
    if(k>=n)
    {
        cout<<arra[n-1]-arra[0]<<endl;
        return 0;

    }
    ll dp[n+5]= {0};
    dp[0]=0;
    dp[1]=abs(arra[1]-arra[0]);
    ll mi=LLONG_MAX;
    for(int i=2; i<k; i++)
    {
        mi=LLONG_MAX;
        for(int j=i-1; j>=0; j--)
        {

            mi=min(mi,dp[j]+abs(arra[j]-arra[i]));
        }
        dp[i]=mi;

    }
    for(int i=k; i<n; i++)
    {
        mi=LLONG_MAX;


        for(int j=(i-k); j<i; j++)
        {
            //cout<<j<<endl;
            mi=min(mi,dp[j]+abs(arra[j]-arra[i]));

        }
        dp[i]=mi;
    }
    cout<<dp[n-1]<<endl;



}


Measured memory_bytes: 5140
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

int main() {
	int n, m;
	cin >> n;
	priority_queue< string, vector<string>, greater<string> >pq;
	vector<string> data;
	string a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		pq.push(a);
	}
	for (int i = 0; i < n; i++) {
		data.push_back(pq.top());
		pq.pop();
	}
	cin >> m;
	bool hantei = false;
	bool hantei2;
	for (int i = 0; i < m; i++) {
		cin >> a;
		hantei2 = true;
		for (int i = 0; i < n; i++) {
			if (data[i] == a) {
				hantei2 = false;
				break;
			} else if (data[i] > a) {
				break;
			}
		}
		if (hantei2) {
			cout << "Unknown "  << a << endl;
		} else {
			if (hantei) {
				cout << "Closed by " << a << endl; 
				hantei = false;
			} else {
				cout << "Opened by " << a << endl;
				hantei = true;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std; 
using ll=long long;
#define endl "\n"
#define F(i,n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repp(i,a,b) for(ll i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ALL(v) v.begin(),v.end()
void solve(){
    
    ll N;
    cin>>N;
    ll A[N];
    F(i,N)  cin>>A[i];
    ll B[N];

    F(i,N)  B[i]=A[i];

    sort(B,B+N);

    F(i,N){
        if(A[i]!=B[N-1]){ cout<<B[N-1]<<endl; }
        else{ cout<<B[N-2]<<endl; }
    }

}
signed main(){
    fast;
     
    solve();
 
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    int x_side = x2 - x1;
    int y_side = y2 - y1;
    
    cout << x2 - y_side << " " << y2 + x_side << " " << x1 - y_side << " " << y1 + x_side;
   
    return 0;
}


Measured memory_bytes: 3560
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

max_A = max(A)
next_A = sorted(A, reverse=True)[1]
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(next_A)

Measured memory_bytes: 13316
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll X, Y;
    cin >> X >> Y;
    if((X + Y) % 3 != 0){
        puts("0");
        return 0;
    }
    ll n = (-1 * X + 2 * Y) / 3;
    ll m = (2 * X - Y) / 3;
    COMinit();
    cout << COM(n + m, n) << endl;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in(), a = in(), b = in();

  cout << min(a, b) << " " << max(0, a + b - n) << endl;
}


Measured memory_bytes: 256