akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> table(2, vector<int>(n, 0));
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> table[i][j];
        }
    }

    int max_ans = 0;
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j <= i; j++)
        {
            count += table[0][j];
        }
        for (int j = i; j < n; j++)
        {
            count += table[1][j];
        }
        max_ans = max(max_ans, count);
    }
    cout << max_ans << endl;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i

def divisions(n)
    divs=[]
    1.upto((n**0.5).to_i+1) do|i|
        if (n%i).zero?
            divs.push(i)
            divs.push(n/i)
        end
    end
    return divs
end

divs=divisions(N)
ans=Float::INFINITY
i=0
while i<divs.size
  val=divs[i]+divs[i+1]-2
  ans=val if ans>val
  i+=2
end
puts ans

Measured memory_bytes: 1916
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    if(n%2==0){
        ll res=0;
        rep3(i,1,30){
            ll k=pow(5,i)*2;
            res+=n/k;
           // cout<<i<<" "<<n/k<<endl;
        }
        cout<<res<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
const double g = 9.8;
const double EPS = 1e-8;
namespace solver{
    int n;
    double v, gx, gy;
    double x1[50], x2[50], y1[50], y2[50];

    double calc_y(double vx, double vy, double x){
        double t = x / vx;
        return vy * t - g * t * t / 2;
    }

    int sign(double x){
        if(x > EPS) return 1;
        if(x < -EPS) return -1;
        return 0;
    }
    
    int comp(double lb, double ub, double x){
        if(x < lb + EPS) return -1;
        if(x > ub - EPS) return 1;
        return 0;
    }

    bool check(double bx, double by){
        double a = g * g / 4.0;
        double b = g * by - v * v;
        double c = bx * bx + by * by;
        double D = b * b - 4 * a * c;
        //printf("D:%f\n", D);
        if(D < 0) return false;
        for(int s = -1; s <= 1; s += 2){
            double tt = (-b + s * sqrt(D)) / (2 * a);
            //printf("tt:%f\n", tt);
            if(tt < 0) continue;
            double t = sqrt(tt);
            double vx = bx / t;
            double vy = (by + g * t * t / 2) / t;
            assert(sign(vx * vx + vy * vy - v * v) == 0);
            double fh = calc_y(vx, vy, gx);
            if(sign(fh - gy) < 0) continue;
            bool ok = true;
            for(int i = 0; i < n; i++){
                if(x1[i] >= gx) continue;
                if(comp(x1[i], x2[i], gx) == 0 && comp(y1[i], y2[i], gy) <= 0 && comp(y1[i], y2[i], fh) >= 0) {
                    ok = false;
                }
                int yl = comp(y1[i], y2[i], calc_y(vx, vy, x1[i]));
                int yr = comp(y1[i], y2[i], calc_y(vx, vy, x2[i]));
                int xh = comp(x1[i], x2[i], vx * vy / g);
                int yh = comp(y1[i], y2[i], calc_y(vx, vy, vx * vy / g));
                if(xh == 0 && yh >= 0 && yl <= 0) ok = false;
                if(yl * yr <= 0) ok = false;
            }
            if(ok) return true;
        }
        return false;
    }
    bool solve(){
        cin >> n;
        cin >> v >> gx >> gy;
        REP(i, n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        REP(i, n) x2[i] = min(x2[i], gx);
        bool ans = false;
        ans |= check(gx, gy);
        REP(i, n){
            ans |= check(x1[i], y2[i]);
            ans |= check(x2[i], y2[i]);
        }
        return ans;
    }
}

int main(){
    cout << (solver::solve() ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

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

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  ll i,j,cnt=0;
    ll k,x;
    cin>>k>>x;
    if(500*k>=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
  int D;
  cin>>D;
  if(D==22){
    cout<<"Christmas Eve Eve Eve"<<endl;
  }
  else if(D==23){
    cout<<"Christmas Eve Eve"<<endl;
  }
  else if(D==24){
    cout<<"Christmas Eve"<<endl;
  }  
  else if(D==25){
    cout<<"Christmas"<<endl;
  }
  
  return 0;
}
    

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long Z, long long W, std::vector<long long> a){
    if(N == 1) {
        cout << abs(W-a[N-1]) << endl;
    } else {
        cout << max(abs(W-a[N-1]), abs(a[N-1]-a[N-2])) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long Z;
    scanf("%lld",&Z);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, Z, W, std::move(a));
    return 0;
}



Measured memory_bytes: 256
a,b,n = map(int,input().split())
import math
if n < b:
    floor_tmp = math.floor(a * n / b) - a * math.floor(n / b)
else:
    n = b - 1
    floor_tmp = math.floor(a * n / b) - a * math.floor(n / b)
print(floor_tmp)

Measured memory_bytes: 9188
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;
const int MAX_C = 2100;
const LL MOD = 1e9 + 7;
LL com[MAX_C][MAX_C];

template<typename T>
struct Combination {
    vector<T> fact, rfact, inv;
    const LL MOD = 1e9 + 7;
    Combination(int size) : fact(size + 1), rfact(size + 1), inv(size + 1) {
        fact[0] = fact[1] = 1;
        rfact[0] = rfact[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= size; i++) {
            fact[i] = fact[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            rfact[i] = rfact[i - 1] * inv[i] % MOD;
        }
    }
    LL com(int n, int k) {
        if (n < k) return 0;
        if (n < 0 or k < 0) return 0;
        return fact[n] * (rfact[k] * rfact[n - k] % MOD) % MOD;
    }

};
map<LL, LL> prime_factorize(LL n) {
    map<LL, LL> prime_factors;

    for (LL i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++prime_factors[i];
            n /= i;
        }
    }
    if (n != 1) prime_factors[n] = 1;
    return prime_factors;
}
int main() {
    int n; LL m; cin >> n >> m;

    auto factors = prime_factorize(m);
    Combination<LL> com(210000);

    LL ans = 1;
    for (auto it : factors) {
        ans = (ans * com.com(it.second + n - 1, n - 1)) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 5248
#include<stdio.h>
int main(){
	int a[5];
	for(int i = 0; i <= 2; i++){
		scanf("%d", &a[i]);
	}
	if(a[0] == 5 && a[1] == 7 && a[2] == 5 ||
		a[0] == 7 && a[1] == 5 && a[2] == 5||
		a[0] == 5 && a[1] == 5 && a[2] == 7){
		printf("YES\n");
		}
		else{
			printf("NO\n");
		}
		return 0;
	}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		Map<String, Integer> blueCards = new HashMap<String, Integer>();
		for (int i = 0; i < n; i++) {
			String s = sc.nextLine();
			if (blueCards.containsKey(s)) {
				// 同一文字列登録済ならばvalueをインクリメント
				blueCards.put(s, blueCards.get(s) + 1);
			} else {
				// 初めて登場した文字列はvalue=1で追加
				blueCards.put(s, 1);
			}
		}
		
		int m = Integer.parseInt(sc.nextLine());
		for (int i = 0; i < m; i++) {
			String t = sc.nextLine();
			if (blueCards.containsKey(t)) {
				// 同一文字列登録済ならばvalueをデクリメント
				blueCards.put(t, blueCards.get(t) - 1);
			}
			// 青いカードに存在しない文字の場合は、そもそもプラスになりえないので読み捨て
			// 青いカードがすべてマイナスならば0が最大となる
			// (-1となりえる文字列の組み合わせの最大数は99種類だが長さ10の英小文字の文字列の組み合わせはそれ以上に存在し得る)
		}
		
		// Mapをvalueの降順にソートする
		List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(blueCards.entrySet());
		Collections.sort(list_entries, (o1, o2) -> {return o2.getValue().compareTo(o1.getValue());});
		
		int max = list_entries.get(0).getValue();
		
		if (max < 0) {
			System.out.println(0);
		} else {
			System.out.println(max);
		}
		
		sc.close();
	}
}

Measured memory_bytes: 27860
#include <iostream>
#include<string>
#include<vector>
using namespace std; int i = 0;
int n; vector<string> s(60); int t[60]; string as; int ans = 0; int y = 0;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
    }
    cin >> as;
    if (n != 1) {
        int k = 0;
        for (k = 0; k < n; k++) {
            if (s[k] == as) {
                break;
            }
        }
        y = k;
        for (int j = y + 1; j < n; j++) {
            ans += t[j];
        }
        cout << ans << endl;
    }
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
N=int(input())
U,R,D,L=[],[],[],[]
for i in range(N):
  x,y,a=input().split()
  x,y=int(x),int(y)
  if a=='U':
    U.append((x,y))
  elif a=='R':
    R.append((x,y))
  elif a=='D':
    D.append((x,y))
  elif a=='L':
    L.append((x,y))

G={}
for x,y in U:
  if x not in G:
    G[x]=[(y,'U')]
  else:
    G[x].append((y,'U'))
for x,y in D:
  if x not in G:
    G[x]=[(y,'D')]
  else:
    G[x].append((y,'D'))  

time=10**10
for i in G.values():
  a=len(i)
  i=sorted(i)
  for j in range(a-1):
    if i[j][1]=='U' and i[j+1][1]=='D':
      t=(i[j+1][0]-i[j][0])*5
      time=min(t,time)
G={}
for x,y in R:
  if y not in G:
    G[y]=[(x,'R')]
  else:
    G[y].append((x,'R'))
for x,y in L:
  if y not in G:
    G[y]=[(x,'L')]
  else:
    G[y].append((x,'L'))  

for i in G.values():
  a=len(i)
  i=sorted(i)
  for j in range(a-1):
    if i[j][1]=='R' and i[j+1][1]=='L':
      t=(i[j+1][0]-i[j][0])*5
      time=min(t,time)
#UとR
G={}
for x,y in U:
  if x+y not in G:
    G[x+y]=[(y,'R')]
  else:
    G[x+y].append((y,'R'))
for x,y in R:
  if x+y not in G:
    G[x+y]=[(y,'U')]
  else:
    G[x+y].append((y,'U'))
for i in G.values():
  a=len(i)
  i=sorted(i) 
  for j in range(a-1):
    if i[j][1]=='R' and i[j+1][1]=='U':
      t=(i[j+1][0]-i[j][0])*10
      time=min(t,time)
#DとR
G={}
for x,y in D:
  if x-y not in G:
    G[x-y]=[(y,'D')]
  else:
    G[x-y].append((y,'D'))
for x,y in R:
  if x-y not in G:
    G[x-y]=[(y,'R')]
  else:
    G[x-y].append((y,'R'))
for i in G.values():
  a=len(i)
  i=sorted(i) 
  for j in range(a-1):
    if i[j][1]=='R' and i[j+1][1]=='D':
      t=(i[j+1][0]-i[j][0])*10
      time=min(t,time)
#DとL
G={}
for x,y in D:
  if x+y not in G:
    G[x+y]=[(y,'D')]
  else:
    G[x+y].append((y,'D'))
for x,y in L:
  if x+y not in G:
    G[x+y]=[(y,'L')]
  else:
    G[x+y].append((y,'L'))
for i in G.values():
  a=len(i)
  i=sorted(i) 
  for j in range(a-1):
    if i[j][1]=='L' and i[j+1][1]=='D':
      t=(i[j+1][0]-i[j][0])*10
      time=min(t,time)
#最後UL
G={}
for x,y in U:
  if x-y not in G:
    G[x-y]=[(y,'U')]
  else:
    G[x-y].append((y,'U'))
for x,y in L:
  if x-y not in G:
    G[x-y]=[(y,'L')]
  else:
    G[x-y].append((y,'L'))
for i in G.values():
  a=len(i)
  i=sorted(i) 
  for j in range(a-1):
    if i[j][1]=='U' and i[j+1][1]=='L':
      t=(i[j+1][0]-i[j][0])*10
      time=min(t,time)
if time==10**10:
  print('SAFE')
else:
  print(time)

Measured memory_bytes: 192340
import java.io.*;

public class Main {
	 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String s;
        while ((s = br.readLine()) != null) {
            String[] lc = s.split(" ");
            double a = Double.parseDouble(lc[0]);
            double b = Double.parseDouble(lc[1]);
            double c = Double.parseDouble(lc[2]);
            double d = Double.parseDouble(lc[3]);
            double e = Double.parseDouble(lc[4]);
            double f = Double.parseDouble(lc[5]);
            
            double z = a*e - b*d;
            
            double x = (e*c-b*f)/z;
            double y = (-d*c + a*f)/z;
             
            System.out.println(String.format("%.3f %.3f", Math.round(x*1000)/1000.0 , Math.round(y*1000)/1000.0));
        }
 
    }
}

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


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

    map<int,int> M;
    rep(i,N){
        int A; cin >> A;
        M[A]++;
    }

    priority_queue<int, vector<int>, greater<int>> Q;
    for(auto p : M){
        Q.push(p.second);
    }

    int ans = 0;
    while(Q.size() > K){
        int m = Q.top();
        ans += m;
        Q.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 10748
use itertools::Itertools;

fn main() {
    proconio::input! {
    a:String,
  }
    let e=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',];
    let mut v=[0;26];
    let a=a.chars().collect_vec();
    for i in 0..a.len() {
        for j in 0..26 {
            if a[i]==e[j] {
                if v[j]==1{println!("no");std::process::exit(0)}
                v[j]=1;
            }
        }
    }
    println!("yes")
}


Measured memory_bytes: 2196
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top, X[1000];

void push(int y)
{
  X[++top] = y;
}

int pop()
{
  top--;
  return X[top+1];
}


int main()
{
  int a, b;
  char c[100];
  top = 0;

  while(scanf("%s", c) != EOF)
    {
      if(c[0] == '+')
	{
	  a = pop();
	  b = pop();
	  push(a + b);
	}
      else if(c[0] == '-')
	{
	  a = pop();
	  b = pop();
	  push(b - a);
	}
      else if(c[0] == '*')
	{
	  a = pop();
	  b = pop();
	  push(a * b);
	}
      else
	{
	  push(atoi(c));
	}
    }
  printf("%d\n", pop());
  return 0;
}




Measured memory_bytes: 2144
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...


    
    int n,m;
    
    cin >> n >> m;
    
    int a[m];
    
    for(int i=0; i<m; i++) std::cin >> a[i];

    int total =0;

    for(int i=0; i<m; i++) {
        total = total + a[i] ;
    }
    
    if((n-total) < 0)
        cout << -1 << endl;
    else
        cout << n-total << endl;
    
    return 0;
    
}


Measured memory_bytes: 3604
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n, x = [next_int() for _ in range(2)]
    a = sorted([next_int() for _ in range(n)])
    ans = 0

    for i, ai in enumerate(a):
        if x < ai or (i == n - 1 and x != ai):
            break
        ans += 1
        x -= ai

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int cmp(int x,int y)
{
	return x<y;
}
int main()
{
	int sum=0;
	int a[10];
	int b[10];
	int k=0;
	for(int i=0;i<5;i++)
	{
		cin>>a[i];
		b[i]=a[i]%10;

	}
	for(int j=1;j<5;j++)
	{
		if((b[k]>b[j]&&b[j]!=0)||(b[k]==0&&b[j]!=0)) 
		{
			k=j;

		}
	}
	for(int i=0;i<5;i++)
	{
		if(i!=k&&b[i]!=0) sum+=a[i]-b[i]+10;
		else if(i!=k&&b[i]==0) sum+=a[i];
	}

	cout<<sum+a[k];
	
return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int num1=1,num2=0,num3=0;
    char num = sa[0];
    while(1){
        if(num=='c'){
            if(num3>sc.size()-1)break;
            num = sc[num3];
            num3++;
        }
        else if(num=='b'){
            if(num2>sb.size()-1)break;
            num = sb[num2];
            num2++;
        }
        else if(num=='a'){
            if(num1>sa.size()-1)break;
            num = sa[num1];
            num1++;
        }
    }
    cout << (char)(num-32) << endl; 
    return 0;
}  


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s;
    cin >> s;
    string ans = s.substr(0, 3);
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define io std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007;
using namespace std;
int main()
{
    io;
    int n;
    cin>>n;
    vector <int> v(n);
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        m[v[i]]=i+1;
    }
    for(auto i : m)
        cout<<i.second<<" ";
}


Measured memory_bytes: 5888
import heapq

n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,reverse=True,key=lambda x:x[1])
q=[]
v=set()
s=0
for t,d in arr[:k]:
  s+=d
  if t in v:
    heapq.heappush(q,d)
  else:
    v.add(t)
s+=len(v)**2
ans=s
for t,d in arr[k:]:
  if t not in v and len(q)!=0:
    z=heapq.heappop(q)
    s+=d+2*len(v)+1-z
    v.add(t)
    ans=max(ans,s)
print(ans)

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

long long calc(long long x) {
  vector<long long> v = {x, 1, x + 1, 0};
  return v[abs(x % 4)];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  if (a == 0 && b == 0) {
    cout << 0 << '\n';
  } else if (a == 0) {
    cout << (calc(b) ^ calc(0) ^ 0) << '\n';
  } else {
    cout << (calc(b) ^ calc(a - 1)) << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
lis=sorted(lis)
#print(lis)

for i in range(1,n):
    lis[i]=lis[i]%lis[0]
lis.append(0)
lis=sorted(list(set(lis)))
    
while len(lis)>2:
    for i in range(2,len(lis)):
        lis[i]=lis[i]%lis[1]
    lis.append(0)
    lis=sorted(list(set(lis)))
#print(lis)
print(lis[-1])
#print(lis[0])

Measured memory_bytes: 14636
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;



public class Main{

        static final Scanner sc=new Scanner(System.in);






        public static void main(String[]args){
                int N=sc.nextInt();
                int M=sc.nextInt();
                int X=sc.nextInt();
                int Y=sc.nextInt();
                int[]x=new int[N];
                int[]y=new int[M];
                for(int i=0;i<N;i++){
                        x[i]=sc.nextInt();
                }
                for(int i=0;i<M;i++){
                        y[i]=sc.nextInt();
                }
                Arrays.sort(x);
                Arrays.sort(y);
                boolean ok=false;
                for(int i=X+1;i<=Y;i++){
                        if((y[0]>=i)&&(x[N-1]<i)){
                                ok=true;

                        }
                }
                if(ok){
                        System.out.println("No War");
                }else{
                        System.out.println("War");
                }
                

                


                



        }








        
        private static int gcd(int m, int n) {
                if(m < n) return gcd(n, m);
                if(n == 0) return m;
                return gcd(n, m % n);
            }






}


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

vector < long long > dp[110];
long long n, w;
vector <pair <long long, long long> > items;

int main(){

	scanf("%lld %lld", &n, &w);
	for(int i = 0 ; i < n ; i++){
		long long a, b;
		scanf("%lld %lld" , &a, &b);
		items.push_back(make_pair(a, b));
	}

	for(int i = 0 ; i <= w ; i++){
		dp[0].push_back(0);
	}
	for(int i = 0 ; i < n ; i++){
		dp[i+1].push_back(0);
	}

	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= w ; j++){
			if(items[i-1].first <= j){
				dp[i].push_back(max(dp[i-1][j], dp[i-1][j - items[i-1].first] + items[i-1].second));
			}
			else {
				dp[i].push_back(dp[i-1][j]);
			}
		}
	}

	printf("%lld\n", dp[n][w]);
	return 0;

}

Measured memory_bytes: 80184
#include <bits/stdc++.h>
using namespace std;
int k, a[111], d[100001], n;
int main() {
	for(int i = 1; i <= 100000; i <<= 1) d[i] = 1;
	cin >> n; 
	if(d[n]) {printf("No\n"); return 0;} 
	printf("Yes\n");
	printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n", n + 1, n + 1, n + 2, n + 2, n + 3);
	for(int i = 4; i < n; i += 2){
		printf("%d %d\n", i, 1 + n); printf("%d %d\n", i + 1, 1 + n);
		printf("%d %d\n", i + n, i + 1); printf("%d %d\n", i + n + 1, i);
	}
	if(n % 2 == 0){
		for(int i = 2; i <= n; i++){
			int p = i ^ 1 ^ n;
			if(p < n && p > 1) {
				if(i == 2) printf("%d %d\n", i + n, n);
				else printf("%d %d\n", i, n);
				printf("%d %d\n", p, n + n);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 2816
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]
b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Measured memory_bytes: 45208
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static int V;
	static int []match;
	static boolean []used;
	static Map<Integer, List<Integer>> G = new HashMap<Integer, List<Integer>>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]a = new int[N];
		int[]b = new int[N];
		int[]c = new int[N];
		int[]d = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		sc.close();
		V = 2 * N;
		match = new int[V];
		used = new boolean[V];
		// 隣接リストを作成
		for(int i = 0; i < N; i++) {
			List<Integer> list1 = new ArrayList<Integer>();
			for(int j = 0; j < N; j++) {
				if(a[i] < c[j] && b[i] < d[j]) {
					list1.add(N + j);
					if(G.containsKey(N + j)) {
						G.get(N + j).add(i);
					}else {
						List<Integer> list2 = new ArrayList<Integer>();
						list2.add(i);
						G.put(N + j, list2);
					}
				}
			}
			G.put(i, list1);
		}
		int max = bipatricleMatching();
		System.out.println(max);
	}
	static boolean dfs(int v) {
		used[v] = true;
		if(!G.containsKey(v)) return false;
		for(int i = 0; i < G.get(v).size(); i++) {
			int u = G.get(v).get(i);
			int w = match[u];
			if(w < 0 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
	static int bipatricleMatching() {
		int res = 0;
		Arrays.fill(match, -1);
		for(int v = 0; v < V; v++) {
			if(match[v] < 0) {
				Arrays.fill(used, false);
				if(dfs(v)) res++;
			}
		}
		return res;
	}
}

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

for i in range(N):
    A.append(A[i]+K)
    
ans = 10**9+7

for i in range(N):
    ans = min(ans,A[i+(N-1)] - A[i])
    
print(ans)

Measured memory_bytes: 26444
p = 0
f = 0
n, a, b = map(int, input().split())
for i in input():
    if i == "a" and p < a+b:
        p += 1
        print("Yes")
    elif i == "b" and p < a+b and f < b:
        p += 1
        f += 1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n, k;
    cin >> n >> k;
    cout << n - k + 1 << "\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9+9;
int a[1007],b[1007];

int main()
{
    int a,b,c,ma=0;
    vector <int> v;
    cin>>a>>b>>c;
    for(int i=a;i<a+c;i++){
        if(i<=b){
            v.push_back(i);
            ma=max(ma,i);
        }
        else break;
    }
    for(int i=b;i>ma;i--){
        if(i>b-c) v.push_back(i);
    }

    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<endl;
    }

    return 0;
}
// gotcha;


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
  int n,q,t;
  string name;
  queue<pair<string,int> >Q;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>name>>t;
    Q.push(make_pair(name,t));
  }

  pair<string,int>u;
  int elaps=0,a;
  while(!Q.empty()){
    u=Q.front();
    Q.pop();
    a=min(u.second,q);
    u.second-=a;
    elaps+=a;
    if(u.second>0){
      Q.push(u);
    }else{
    cout<<u.first<<" "<<elaps<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4404
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T; cin >> T;
    const vector<vector<char>> data = {
        {},
        {'.',',','!','?',' '},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
    };
    while (T--) {
        string S; cin >> S;
        int N = S.size();
        string ans = "";
        int cnt = 0;
        rep(i,N) {
            if (S[i] != '0') cnt++;
            else {
                if (cnt != 0) {
                    ans += data[S[i-1]-'0'][(cnt-1)%data[S[i-1]-'0'].size()];
                    cnt = 0;
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int c = 0;
        for (int i = 0 ; i < s.length() ; i++) {
            int n = Integer.valueOf(s.substring(i, i+1));
            c += n;
        }
        System.out.println(c % 9 == 0 ? "Yes" : "No");

    }

}


Measured memory_bytes: 49756
N, M = map(int, input().split())
v = [[] for _ in range(N)]
for i in range(M) :
    a, b = map(int, input().split())
    v[a-1].append((b-1, i))
    v[b-1].append((a-1, i))

def dfs(n) :
    queue = [0]
    visited = [False] * N
    visited[0] = True
    counter = 1
    while queue :
        cur = queue.pop()
        for nex, i in v[cur] :
            if i == n : 
                continue
            if not visited[nex] :
                counter += 1
                queue.append(nex)
                visited[nex] = True
    
    return counter != N

ret = 0
for i in range(M) :
    if dfs(i) :
        ret += 1
print(ret)

Measured memory_bytes: 39408
import Data.List

main :: IO ()
main = do
  s <- getLine
  print $ solve s

-- |
-- >>> solve "RRS"
-- 2
--
-- >>> solve "SSS"
-- 0
--
-- >>> solve "RSR"
-- 1
--
-- prop> solve xs >= 0
--
-- prop> solve xs == solve (reverse xs)
--
-- prop> solve xs <= length (filter (== 'R') xs)
--
solve :: String -> Int
solve = foldr max 0 . map length . filter (\xs -> head xs == 'R') . group


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int ans=t.size();
	rep(i,n+1-t.size()){
		string now=s.substr(i,t.size());
		int cnt=0;
		rep(j,t.size()){
			if(t[j]!=now[j]) cnt++;
		}
		chmin(ans,cnt);
	}
	cout<<ans<<endl;
}

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

int main() {
    vector<int> vec(3);
    rep(i, 3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    cout << vec[0]*vec[1]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#define V_MAX 10000
#define E_MAX 100000
using namespace std;

int V,E;
bool check[V_MAX+1];//頂点が探索済みかどうか保管
queue<int> G[V_MAX+1];//隣接リスト
vector<int> TO;

void dfs(int num){
	if(check[num] == true)return;
	check[num] = true;
	while(!G[num].empty()){
		dfs(G[num].front());G[num].pop();
	}
	TO.push_back(num);
	return;
}

void solve(){
	for(int i = 0;i < V;i++)check[i] = false;
	int vs,ve;
	for(int i = 0;i < E;i++){
		cin >>vs >>ve;
		G[vs].push(ve);
	}
	for(int i = 0;i < V;i++)dfs(i);
	while(!TO.empty()){cout <<TO.back() <<endl;TO.pop_back();}
	return;
}

int main(){
	cin >>V >>E;
	solve();

	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (a > 0 && c > 0) {
        c -= b;
        a -= d;
    }
    if (c <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
from collections import defaultdict
from itertools import product

N, M = map(int, input().split())

d = defaultdict(set)
res = 0

for key in range(1, M+1): # keyは電球を指定
    l = list(map(int, input().split()))
    l.pop(0)
    for i in l:
        d[key].add(i)  # dict = {(電球番号(key): [スイッチ番号(i), ...],...}

p = list(map(int, input().split()))

for a in product(*((0, x) for x in range(1, N+1))):
    light = 0 # 光っている電球の個数
    for key in range(1, M+1):
        count = len(d[key] & set(a)) # 電球番号(key)のスイッチがONになっている個数
        if count%2 == p[key-1]:
            light += 1
    if light == M:
        res += 1

print(res)

Measured memory_bytes: 3316
#include<iostream>
#include<string>

using namespace std;


int main(){
	int num,i;
	string str,tmp;
	cin >> str;
	num = str.length();
	tmp = str;
	for(i = 0; i < num ; i++)
		str[i] = tmp[num-i-1];
	cout << str << endl;
}

Measured memory_bytes: 1176
def myAnswer(L:int,R:int) -> int:
   ans = []
   for i in range(L,R):
      for j in range(L+1,R+1):
         if(i * j)% 2019 == 0:
            return 0
         ans.append((i * j) % 2019)
   return min(ans)

def modelAnswer():
   return
def main():
   L,R = map(int,input().split())
   print(myAnswer(L,R))
if __name__ == '__main__':
   main()

Measured memory_bytes: 10496
#include<iostream>

using namespace std;

int gcd(int, int);

int main(){
  int x, y ,d;

  cin >> x >> y;
  d = gcd(x, y);
  cout << d << endl;
  return 0;
}

int gcd(int x, int y){
  if(x%y ==0)return y;
  return gcd(y, x%y);
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll A,B,Q;

int main(){
    cin >> A >> B >> Q;
    ll s[100100],t[100100];
    ll x;
    ll d[8];
    s[0] = -INF; s[A+1] = INF;
    for(ll i = 1; i <= A; i++) cin >> s[i];
    t[0] = -INF; t[B+1] = INF;
    for(ll i = 1; i <= B; i++) cin >> t[i];
    for(ll i = 0; i < Q; i++){
        cin >> x;
        ll* u = lower_bound(s,s+A+2,x);
        ll* v = lower_bound(t,t+B+2,x);

        d[0] = x - min(*(u-1),*(v-1));
        d[1] = x - *(u-1) + *v - *(u-1);
        d[2] = x - *(v-1) + *u - *(v-1);
        d[3] = max(*v,*u) - x;
        d[4] = *v - x + *v - *(u-1);
        d[5] = *u - x + *u - *(v-1);

        ll ans = d[0];
        for(ll j = 1; j <= 5; j++){
            ans = min(ans, d[j]);
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

class SegTree {
public:
  ////////////////////////////////////////////////////////
  // monoid
  using X = long long;
  X X_dot_X(const X &v1, const X &v2) {
    return max(v1, v2);
  }
  const X X_unit = 0;
  ////////////////////////////////////////////////////////
  typedef size_t idx_type;
  
  vector<X> data;

  idx_type n;
	
  SegTree(idx_type n_) {
    n = 1;
    while(n <= size_t(n_)) {
      n *= 2;
    }
    data.resize(n * 2 - 1, X_unit);
  }
  ~SegTree() {}
  
  X query(idx_type a, idx_type b, idx_type k, idx_type l, idx_type r) {
    if(r <= a || b <= l) {
      return X_unit;
    }
		
    if(a <= l && r <= b) {
      return data[k];
    }
    else {
      X vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return X_dot_X(vl, vr);
    }
  }
  
  X query(idx_type a, idx_type b) {
    return query(a, b, 0, 0, n);
  }
	
  void update(idx_type i, X x) {
    i += n - 1;
    data[i] = x;
    while(i > 0) {
      i = (i - 1) / 2;
      data[i] = X_dot_X(data[i*2+1], data[i*2+2]);
    }
  }
};

int main(int argc, char *argv[]) {
  i64 N, K, i;
  cin >> N >> K;

  vi A(N);
  REP(0, N, i) {
    cin >> A[i];
  }

  const i64 MAX = 300000LL + 1LL;
  SegTree tree(MAX);

  REP(0, N, i) {
    i64 low = A[i] - K;
    i64 high = A[i] + K + 1;
    low = max(0LL, low);
    high = min(high, MAX);

    i64 val = tree.query(low, high) + 1;    
    tree.update(A[i], val);
  }

  cout << tree.query(0, MAX) << endl;

  return 0;
}


Measured memory_bytes: 13828
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  ll n, m, k; cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  
  ll all_time = 0;
  rep(i,m) all_time += b[i];
  int b_cnt = m;
  int ans = 0;
  rep(i,n+1){
    while(b_cnt>0 && all_time>k){
      b_cnt--;
      all_time -= b[b_cnt];
    }
    if(all_time > k) break;
    ans = max(ans, b_cnt+i);
    if (i==n) break;
    all_time += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 6324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<">"<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define ce cout<<"\n"


int main()
{
    int n, m=0;
    cin>>n;
    map<string,int > hsh;
    string s;
    f(i, n)
    {
        cin>>s;
        hsh[s]++;
    }
    for(auto it=hsh.begin(); it!=hsh.end(); it++)
    {
        m = max(m, it->second);
    }
    for(auto it=hsh.begin(); it!=hsh.end(); it++)
    {
        if(it->second == m)
            cout<<it->first<<'\n';
    }
    return 0;
}

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

typedef long long ll;

#define PB push_back
#define MP make_pair

const ll MOD = 1000000007;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, m; cin >> n >> m;
    unordered_set<ll> a;
    for (ll i = 0; i < m; ++i) {
        ll ai; cin >> ai;
        a.insert(ai);
    }
    vector<ll> dp(n+1);
    dp[0] = 1;
    for (ll i = 0; i < n; ++i) {
        for (ll j = i + 1; j <= min(n, i + 2); ++j) {
            if (a.count(j) == 0) {
                dp[j] += dp[i];
                dp[j] %= MOD;
            }
        }
    }
    cout << dp[n] << "\n"; 
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 5156
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
            for (int i = 0; i < n; i++) {
                map.put(in.nextInt(), in.nextInt());
            }
            Map.Entry<Integer, Integer> entry = map.lastEntry();
            out.println(entry.getKey() + (entry.getValue()));
        }

    }
}



Measured memory_bytes: 100172
# -*- coding: utf-8 -*-


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 50


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


def exEuclid(a, mod):
    b = mod
    s, u = 1, 0
    while b:
        q = a // b
        a, b = b, a % b
        s, u = u, s - q * u
    return a, s % mod

def crt(R, M):
    assert len(R) == len(M)
    N = len(R)
    r0, m0 = 0, 1
    for r, m in zip(R, M):
        assert m >= 1
        r %= m
        if m0 < m:
            r0, r = r, r0
            m0, m = m, m0
        if m0 % m == 0:
            if r0 % m != r:
                return (0, 0)
            continue
        g, im = exEuclid(m0, m)
        u = m // g
        if (r - r0) % g:
            return (0, 0)
        x = (r - r0) // g % u * im % u
        r0 += x * m0
        m0 *= u
        if r0 < 0:
            r0 += m0
    return (r0, m0)

@mt
def slv(N):
    def f(n):
        return (n+1)*n // 2

    cand = list(divisor(2*N))
    cand.sort()
    ans = INF
    for x in cand:
        kc, _ = crt([0, -1], (x, 2*N//x))
        if kc != 0:
            ans = min(ans, kc)
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 70224
import sys
N = int(input())
r = list(map(int, input().split()))
if min(r) >= 3200:
  print(str(1)+' '+str(N))
  sys.exit()
li = [0 for i in range(9)]
for rates in r:
  if rates >= 3200:
    rates = 3200
  n = rates//400
  li[n] += 1
p = 0
for nums in li[0:8]:
  if nums !=0:
    p += 1
print(str(p)+' '+str(p+li[8]))

Measured memory_bytes: 3064