akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;

	bool zero;
	foreach (i; 0..N)
	{
		if (A[i] == 0)
			zero = true;
	}
	if (zero)
		writeln(0);
	else
	{
		long ans = 1;
		foreach (i; 0..N)
		{
			debug writeln("i:", i, " ans:", ans);
			if (A[i] > 10L^^18 / ans)
			{
				ans = -1;
				break;
			}
			ans *= A[i];
			debug writeln("i:", i, " ans:", ans);
			if (ans > 10L^^18)
			{
				ans = -1;
				break;
			}
		}
		writeln(ans);
	}

	stdout.flush;
	debug readln;
}


Measured memory_bytes: 7024
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[200009];
long long ans,n;
void dfs(int v,int p) {
	for (int i : adj[v]) 
		if (i != p)
			dfs(i,v);
	if (p) ans-= 1LL*(n - max(v,p) + 1)*min(v,p);
}
main() {
	cin >> n;
	for (int i = 0;i < n-1; i++) {
		int a,b;
		cin >>a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		ans += 1ll*(i+1)*(i+2)/2;
	}
	ans += n*(n+1)/2;
	dfs(1,0);
	cout << ans;
}

Measured memory_bytes: 23752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long x = scan.nextLong();
		long ans;
		
		if(a == 0)
			ans = b / x + 1;
		else
			ans = b / x - (a - 1) / x;
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0) v += MOD; }

  Mint operator-() { return Mint(-v); };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0) return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

const int SIZE = 11234567;
mint fact(int n) {
  static vector<mint> factorial = []() {
    vector<mint> _f(SIZE, 1);
    for(int i=1; i<SIZE; i++) _f[i] = _f[i-1] * i;
    return _f;
  }();
  return factorial[n];
}
mint perm(int n, int k) { return n<k ? 0 : fact(n) / fact(n-k); }
mint comb(int n, int k) { return n<k ? 0 : perm(n, k) / fact(k); }

template<class T, int N> struct Poly {
  deque<T> f;
  Poly() { f.assign(N, T{}); }
  Poly(deque<T>& f) : f(f) {}
  Poly(const Poly& g) : f(g.f) {}

  void operator+=(Poly g) { for(int i=0; i<N; i++) f[i]+=g[i]; }
  void operator>>=(int c) { while(c--) f.push_front(T{}), f.pop_back(); }
  void operator<<=(int c) { while(c--) f.push_back(T{}), f.pop_front(); }
  void operator*=(T c) { for(auto& e : f) e *= c; }

  Poly operator+(Poly g) { auto r=Poly(f); r+=g; return r; }
  Poly operator-(Poly g) { auto r=Poly(f); r+=g*(-1); return r; }
  Poly operator>>(int c) { auto r=Poly(f); r>>=min(c,N); return r; }
  Poly operator<<(int c) { auto r=Poly(f); r<<=min(c,N); return r; }
  Poly operator*(T c) { auto r=Poly(f); r*=c; return r; }

  T& operator[](int i) { return f[i]; }
  inline auto begin() { return f.begin(); }
  inline auto end() { return f.end(); }
};

int main() {
  lint S;
  cin >> S;

  Poly<mint, 2123> f;
  f[0] = 1;
  mint ans = 0;
  for(lint i=0; i<S; i++) {
    f >>= 3;
    f = f - (f>>S);
    partial_sum(f.begin(), f.end(), f.begin());
    ans += f[S];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
import sys
input=sys.stdin.readline
n,u,v=map(int,input().split())
Edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  Edge[a-1].append(b-1)
  Edge[b-1].append(a-1)


from collections import deque

def BFS(s):
  dist=[-1]*n
  que=deque([s-1])
  dist[s-1]=0
  while que:
    v=que.popleft()
    d=dist[v]
    for w in Edge[v]:
      if dist[w]>-1:
        continue
      dist[w]=d+1
      que.append(w)
  return dist

U_d,V_d=BFS(u),BFS(v)
ans=0
for i in range(n):
  if U_d[i]<V_d[i]:
    ans=max(ans,V_d[i]-1)
print(ans)


Measured memory_bytes: 29420
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 998244353;
ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

const ll MAX = 200001;
ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

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

int main(){
  ll n,m,k; cin >> n >> m >> k; ll anssum = 0;
  
  nCrprep(); //nCrの準備をする関数
  
  ll ans1 = m; //各組でのnCrを除いたm*pow(m-1,n-k-1)みたいな部分を保持する数
  
  //m*pow(m-1,n-k-1)になるまでかけていく
  rep(i,n-k-1){
    ans1 = mod(ans1*(m-1));
  }

  //隣り合う組数をkから0まで変えて足していく
  for(ll i=k; i >= 0; i--){
    anssum += mod(ans1*mod(nCr(n-1,i)));
    ans1 = mod(ans1*(m-1));
    anssum = mod(anssum);
  }
  
  //答えを出力する
  cout << anssum << endl;
  
}


Measured memory_bytes: 8340
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxx=10010;
const int infinity=1<<30;

int main() {
	int n,a,b,c,e;
	vector<pair<int, int> > A[maxx];
	bool flag[maxx];
	int d[maxx];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>e;
			A[a].push_back(make_pair(c,e));
		}
	}
	for(int i=0;i<n;i++){
		flag[i]=false;
		d[i]=infinity;
	}
	priority_queue<pair<int,int> > PQ;
	d[0]=0;
	PQ.push(make_pair(0, 0));
	while(PQ.empty()==0){
		pair<int, int> u=PQ.top();
		PQ.pop();
		//cout<<u.first<<" "<<d[u.first]<<endl;
		flag[u.second]=true;
		int len=A[u.second].size();
		for(int i=0;i<len;i++){
			int v=A[u.second][i].first;
			if(flag[v]==false && d[u.second]+A[u.second][i].second<d[v]){
				d[v]=d[u.second]+A[u.second][i].second;
				PQ.push(make_pair(d[v]*(-1),v));
			}
		}
	}

	for(int i=0;i<n;i++) cout<<i<<" "<<(d[i]==infinity ? -1 : d[i])<<endl;

	return 0;
}


Measured memory_bytes: 8024
#include<iostream>
#include<cmath>

using namespace std;

int main(){
 int n;
 cin >> n;
 int t[n+1],x[n+1],y[n+1];
  t[0]=x[0]=y[0]=0;
  for(int i=1;i<=n;i++) cin >> t[i] >> x[i] >> y[i];
  
  
  bool res=true;
  for(int i=0;i<n;i++){
   int dt=t[i+1]-t[i];
   int dl=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt<dl||dt%2!=dl%2) {
      res=false;
      break;
    }
  }
  
 if(res) cout << "Yes" << endl;
 else cout << "No" << endl; 

}

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

using namespace std;


int main()
{
	int n;
	cin>>n;
	vector<int> arr(n);

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

vector<int> dp(n);

dp[0] = 0;
dp[1] = abs(arr[1] - arr[0]);

for(int i=2; i<n ; i++)
{
	dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1] , abs(arr[i-2]- arr[i] ) + dp[i-2] );
}


cout<<dp[n-1]<<"\n";


}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int A, B;
    cin >> A >> B;
    if (A <= 8 && B <= 8) {
        print("Yay!");
    } else {
        print(":(");
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
l, r = gets.split.map(&:to_i)

mn = 2019
1.upto(5000) do |k|
  i = l + k
  break if i > r
  k.times do |b|
    j = l + b
    mn = [(i*j) % 2019, mn].min
    #p [i, j, (i*j)%2019]
    if mn == 0
      puts 0
      exit 0
    end
  end
end

puts mn


Measured memory_bytes: 1788
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  int n;cin >> n;
  int t = 0;
  loop(i,1,n+1) t += i;
  cout << t << endl;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    int n,x;
    while(scanf("%d%d",&n,&x)&&(n!=0||x!=0)){
        int ans=0;
        for(int i=1;i<=n;i++){
            int remain=x-i,left=remain/2,right=remain-left;

            int temp=min(max(0,left-i),max(0,n-right+1));
            
            if (left==right) temp=max(0,temp-1);
            // printf("temp=%d\n",temp);
            ans+=temp;
        }

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

    }


    return 0;
}


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

int main(){
  int n,k,q;cin >> n >> k >> q;
  int p[n];rep(i,n)p[i] = k;
  int a[q];
  rep(i,q) {
    cin >> a[i];
    p[a[i]-1] += 1;
  }
  rep(i,n){
    if(p[i] - q <= 0){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
tot = ans

# say we pick some prefix of the bars
# what's the min cost to make that prefix the halfway point?
# never contract, always expand?
pref = 0
for x in a:
    pref += x
    rem = tot - pref
    ans = min(ans, abs(rem - pref))

print(ans)


Measured memory_bytes: 89680
N, W = gets.split.map(&:to_i)
wv = N.times.map { gets.split.map(&:to_i) }

dp =[]
dp[0] = [10 ** 9 + 1] * (10 ** 5 + 1)
dp[0][0] = 0

1.upto(N) do |i|
  dp[i] = [10 ** 9 + 1] * (10 ** 5 + 1)
  0.upto(10 ** 5) do |j|
    if j - wv[i - 1][1] >= 0
      dp[i][j] = [dp[i - 1][j], dp[i - 1][j - wv[i - 1][1]] + wv[i - 1][0]].min
    else
      dp[i][j] = dp[i - 1][j]
    end
  end
end

(10 ** 5).downto(0) do |i|
  if dp[N][i] <= W
    puts i
    break
  end
end


Measured memory_bytes: 93440
def p(F,A,s): # スコアをsにするために最小限必要な修行の回数
    res=0
    for i in range(N):
        res+=max(A[i]-s//F[i],0)
    return res

N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))

F.sort(reverse=True) # 降順で固定
A.sort() # 昇順で固定

l=0
r=max([F[i]*A[i] for i in range(N)])

while r-l>1:
    m=(l+r)//2
    if p(F,A,m)<=K:
        r=m
    else:
        l=m

print(r if p(F,A,0)>K else 0)

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, K;
    cin >> N >> K;

    N -= 2;

    int upper = N * (N + 1) / 2;
    if (upper < K) {
        cout << -1 << endl;
        return;
    }

    vector<vector<int>> G(N + 2, vector<int>(N + 2, 0));

    for (int i = 0; i < N + 2; i++) {
        for (int j = 0; j < N + 2; j++) {
            if (i != j) G[i][j] = 1;
        }
    }

    int cnt = 1;
    while(K > 0) {
        int d = min(K, N - cnt + 1);
        int delcnt = 0;
        for(int j = cnt + 1; j < N + 2; j++) {
            if (delcnt == d) continue;
            if (j == 0 || j == cnt) continue;
            //cout << "del:" << cnt + 1 << ", " << j + 1 << endl;
            G[cnt][j] = 0;
            G[j][cnt] = 0;
            delcnt++;
        }
        cnt++;
        K -= d;
        //cout << "K:" << K << endl;
    }

    vector<pii> ans;
    for (int i = 0; i < N + 2; i++) {
        for (int j = i + 1; j < N + 2; j++) {
            if (G[i][j]) ans.push_back({i, j});
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
    }

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout.setf(ios::fixed);
    //cout.precision(16);
    
    solve();
}

Measured memory_bytes: 384
def solve(p,dif,x)
    dp = Hash.new(-1)
    dp[0] = 0
    c = x
    p.size.times do |i|
        0.upto(c) do |j|
            next if dp[j] == -1
            next if j + p[i] > x
            dp[j+p[i]] = dp[j] + dif[i] if dp[j] + dif[i] > dp[j+p[i]]
        end
    end
    return dp.values.max + x
end
n, d, x = gets.split.map(&:to_i)
p = d.times.map{gets.split.map(&:to_i)}
dif = 1.upto(d-1).map{|i| n.times.map{|j| p[i][j] - p[i-1][j]}}
(d-1).times do |i|
    x = solve(p[i],dif[i],x)
end
p x

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

const int md = (int)1e9 + 7;
inline void add(int &a, int b) {
	a += b;
	if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
	a -= b;
	if (a < 0) a += md;
}
inline int mul(int a, int b) {
	return (int) ((long long) a * b % md);
}
int main() {
#ifdef LOCAL_DEFINE
	freopen("data.in", "rt", stdin);
	// freopen("data.out", "w", stdout);
	auto _start = chrono::high_resolution_clock::now();
#endif

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	vector<vector<int>> dp(n + 1, vector<int>(1 << n));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (a[i][j] == 0) continue;
			for (int mask = 0; mask < (1 << n); mask++) {
				if (mask & (1 << j)) continue;
				add(dp[i + 1][mask | (1 << j)], dp[i][mask]);
			}
		}
	}
	cout << dp[n][(1 << n) - 1] << '\n';

#ifdef LOCAL_DEFINE
	auto _end = chrono::high_resolution_clock::now();
	cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
#endif
	return 0;
}

Measured memory_bytes: 188800
print("Yes" if (lambda x: x==''.join(list(reversed(x))) and x[0:len(x)//2]==''.join(list(reversed(x[0:len(x)//2]))) and x[len(x)-len(x)//2:len(x)]==''.join(list(reversed(x[len(x)-len(x)//2:len(x)]))))(input()) else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int A;
int B;
int C;

int main(){
	
	cin>>A>>B>>C;
	
	if( A <= C && C <= B ) puts("Yes");
	else{			   puts("No");}
	
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using int_greater_PQ = priority_queue<int,vector<int>,greater<int>>;
using d_array=vector<int>;

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

    for(auto&s:S)
    {
        s+=N;
        if(s>'Z')
        {
            auto n=(s-'Z')-1;
            s='A';
            s+=n;
        }
    }

    cout<<S<<endl;
}


Measured memory_bytes: 3644
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 200005;

int n,m;
PII a[N];
int cnt=0,b[N];
priority_queue<int> Q;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),m=read();
	rep(i,1,n) a[i].first=read(),a[i].second=read();
	sort(a+1,a+n+1);
	int ans=0;
	rep(i,1,n) {
		Q.push(-a[i].second);
		if ((int)Q.size()>a[i].first) b[++cnt]=-Q.top(),Q.pop();
	}
	ans=Q.size();
	sort(b+1,b+cnt+1);
	int L=ans,R=m;
	per(i,cnt,1) {
		if (L==R) break;
		if (R>=b[i]) R--;
	}
	ans+=m-R;
	printf("%d\n",n-ans);

	return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int dp[3010][10000];
int main()
{
	int n, t;
	cin >> n >> t;
	vector<P> p(n);
	rep(i,n) cin >> p[i].first >> p[i].second; // 時間、美味しさ。
	SORT(p);
	int ans = 0;
	rep(i,n){
		rep(j,t){
			chmax(dp[i+1][j], dp[i][j]);
			int nj = j + p[i].first;
			if(nj < t)
			chmax(dp[i+1][nj], dp[i][j] + p[i].second);
		}
		int now = dp[i][t-1]+p[i].second; //
		chmax(ans,now);
	}
	cout << ans << endl;

}


Measured memory_bytes: 50676
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  long long int X;
  cin >>X;
  int encontrou =0;
  if(X==2){
    cout << X;
    return 0;
  }

  if(X%2==0){
      X++;
  }
  while(!encontrou){
    encontrou=1;
    for(int i=3;i*i<X;i+=2)
      if(X%i==0){
        encontrou=0;
        break;
      }
    if(encontrou)
      break;
    X+=2;
  }
  printf("%lld",X);
}

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

int main() {
  int num_1, num_2, res;
  char op;
  cin >> num_1 >> op >> num_2;
  if(op == '+') res = num_1 + num_2;
  else res = num_1 - num_2;
  cout << res << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,k,q;
    cin>>n>>k>>q;
    vector<long long> hoge(n,k);
    long long correcter;
    for(long long i=0;i<q;i++){
        cin>>correcter;
        hoge.at(correcter - 1)++;
    }
    for(long long i=0;i<hoge.size();i++){
        if(hoge.at(i)-q<=0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<vector<int>> cnt(2, vector<int>(100005, 0));
    for(int i = 0; i < n; ++i){
        int v;
        cin >> v;
        ++cnt[i % 2][v];
    }
    vector<vector<P>> foo(2);
    for(int i = 0; i < 2; ++i){
        for(int j = 1; j <= 100000; ++j){
            if(cnt[i][j] == 0)  continue;
            foo[i].push_back(P(cnt[i][j], j));
        }
    }
    sort(foo[0].begin(), foo[0].end(), greater<P>());
    sort(foo[1].begin(), foo[1].end(), greater<P>());
    if(foo[0][0].second != foo[1][0].second){
        int n1 = foo[0][0].first, n2 = foo[1][0].first;
        int ans = n - n1 - n2;
        cout << ans << endl;
        return 0;
    }
    int ans = INF;
    if(foo[1].size() == 1){
        int n1 = foo[0][0].first;
        chmin(ans, n - n1);
    }
    else{
        int n1 = foo[0][0].first, n2 = foo[1][1].first;
        chmin(ans, n - n1 - n2);
    }
    if(foo[0].size() == 1){
        int n2 = foo[1][0].first;
        chmin(ans, n - n2);
    }
    else{
        int n1 = foo[0][1].first, n2 = foo[1][0].first;
        chmin(ans, n - n1 - n2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define mod 998244353
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\n"
using namespace std;
void solve1();
void solve()
{
    int T;cin>>T;
    for(int z=1;z<=T;z++)
    {
        solve1();
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve1();
    return 0;
}
void solve1()
{
    int n,d,x,y;cin>>n>>d;
    int ans=0;
    while(n--)
    {
        cin>>x>>y;
        int p=x*x+y*y;
        if(p<=d*d)ans++;
    }
    cout<<ans<<endl;
}


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

int parent[100000],height[100000];

int find(int x){
	if(parent[x] == x) return x;
	else return parent[x] = find(parent[x]);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(height[x] < height[y]){
		parent[x] = y;
	}else {
		parent[y] = x;
		if(height[x] == height[y]) height[x]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}

int main(){
	int n,m,q;
	cin >> n >> m;
	for(int i = 0;i < n;i++) parent[i] = i;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		unite(a,b);
	}
	cin >> q;
	for(int i = 0;i < q;i++){
		int a,b;
		cin >> a >> b;
		if(same(a,b)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3780
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
char s[200005];
int main()
{
	int cnt=0;
	scanf("%s",&s);
	int n=strlen(s);
	string a="",b="";
	for(int i=0;i<n;i++)
	{
		a+=s[i];
		if(a!=b)
		{
			b=a;
			cnt++;
			a="";
		}
	}
	printf("%d\n",cnt);
	return 0;
} 

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
map<ll, ll> mp;
void solve(long long n) {
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        mp[p] += num;
    }
    if (n != 1) mp[n]++;
}
int main() {
    ll n; cin >> n;
    mint ans = 1;
    for(ll i=2;i<=n;i++) {
        solve(i);
    }
    for(auto it=mp.begin();it!=mp.end();it++) {
        ans *= it->second + 1;
    }
    cout << ans.x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
using namespace std;
const int MaxN=1000050;
template <class t> inline void read(t &s)
{
    s=0;
    reg int f=1;
    reg char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(isdigit(c))
        s=(s<<3)+(s<<1)+(c^48),c=getchar();
    s*=f;
    return;
}
char s[MaxN];
signed main(void)
{
    scanf("%s",s+1);
    reg int n=strlen(s+1);
    s[0]=0;
    reg int ans=0;
    for(int i=1;i<=n;++i)
        s[i]-='0';
    for(int i=n;i>=1;--i)
    {
        if(s[i]==10)
        {
            s[i]=0;
            ++s[i-1];
        }
        if(s[i]==5)
        {
            if(s[i-1]>=5)
            {
                ++s[i-1];
                ans+=5;
            }
            else
            {
                ans+=5;
            }
        }
        else if(s[i]<5)
        {
            ans+=s[i];
        }
        else if(s[i]>5)
        {
            ans+=10-s[i];
            ++s[i-1];
        }
    }
    ans+=s[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
 
#define pi 3.1415926535

int main()
{
  int x, y;
  cin >> x >> y;

  if(y % 2 == 1){
    cout << "No";
    return 0;
  }

  for(int turu = 0; turu <= x; turu++){
    int kame = x - turu;
    if(kame * 4 + turu * 2 == y){
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";

  return 0; 
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];
    sort(A.begin(),A.end());
    cout << A[n-1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#define ll long long
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x %= p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll po(ll base, ll powerRaised)
{
    if (powerRaised != 0)
        return (base * po(base, powerRaised - 1));
    else
        return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, n;
    cin >> x >> n;
    ll prev = 0;
    ll ans = INT_MIN;
    ll p, res;
    for (int i = 0; i < n; i++)
    {
        cin >> p;
        if (i != 0)
            ans = max(ans, p - prev);
        else
            res = p;
        prev = p;
    }
    ans = max(ans, x - p + res);
    cout << x - ans;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const int MAX_N = 110;
const int MAX_V = 1010;
const ll INF = 1LL << 60;

vector<vector<ll>> dp(MAX_N,vector<ll>(MAX_N*MAX_V,0));

int main() {
    int N,W;
    cin >> N >> W;
    vecl w(N),v(N);
    REP(i,N) cin >> w[i] >> v[i];
    for(int i = 1; i < MAX_N*MAX_V; i++) dp[0][i] = INF; 
    REP(i,N) REP(j,MAX_N*MAX_V) {
        if(j < v[i]) dp[i+1][j] = dp[i][j];
        else {
            dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans;
    REP(j,MAX_N*MAX_V) if(dp[N][j] <= W) ans = j;
    cout << ans << endl;
}



Measured memory_bytes: 96640
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = list(accumulate([0] + [(1-2*(i%2))*a for i, a in enumerate(A)]))
print(*[(1-2*(i%2))*((S[N]-S[i]) - (S[i]-S[0])) for i in range(N)])


Measured memory_bytes: 109204
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
    ll n;
    cin>>n;
    n--;
    ll temp=1,cnt=1;
    while(n>0)
    {
        temp*=26;
        if(temp<=n)
            n-=temp;
        else
            break;
        cnt++;
    }
    vector<ll> arr(cnt+1);
    arr[cnt]=1;
    for(ll i=cnt-1;i>=0;i--)
        arr[i]=arr[i+1]*26;
    string str="";
    for(ll i=0;i<cnt;i++)
    {
        ll t=0,v=0;
        for(ll j=1;j<=26;j++)
        {
            ll val=j*arr[i+1];
            if(val<=n)
            {
                t=j;
                v=val;
            }
            else
                break;
        }
        str+=('a'+t);
        n-=v;
    }
    cout << str << endl;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n, m;

int main() {

	FAST;

	cin >> n >> m;
	int g = 1;
	for (int i = 1; i * i <= m; i ++) {
		if (m % i == 0) {
			if (i >= n) {
				g = max(g, m / i);
			}
			if (m / i >= n) {
				g = max(g, i);
			}
		}
	}
	cout << g << '\n';
	return 0;
}

Measured memory_bytes: 256
N = 999_999
ar = [*0..N]
2.upto(Math.sqrt(N).to_i) do |i|
  next if ar[i].zero?
  2.upto(N / i) {|j| ar[i * j] = 0}
end

$<.readlines.map(&:to_i).each do |n|
  co = 0
  ar[2..-1].each do |i|
    break if i > n
    co += 1 if i.nonzero?
  end
  puts co
end


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

#define INF 1e9

int main(void){
  int n, input;
  cin >> n;
  
  vector<int> dp(n + 2, INF);
  dp[0] = -INF;
  
  for(int i = 0; i < n; i++){
    cin >> input;
    vector<int>::iterator it
      = upper_bound(dp.begin(), dp.end(), input);
    if(*(it - 1) < input)
      *it = input;
  }

  int ans = 0;
  while(dp[ans + 1] < INF){ ++ans; }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 3140
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	int N;
	cin >> N;
	vint X(N), Y(N), H(N);
	for (int i = 0; i < N; i++)
	{
		cin >> X[i] >> Y[i] >> H[i];
	}



	for (int cx = 0; cx <= 100; cx++)
	{
		for (int cy = 0; cy <= 100; cy++)
		{
			// 高さchの特定
			int ch;
			for (int i = 0; i < N; i++)
			{
				if (H[i] > 0)
				{
					ch = H[i] + abs(cx - X[i]) + abs(cy - Y[i]);
				}
			}

			if (cx == 2 && cy == 2)
			{
				int df = 5;
			}

			for (int i = 0; i < N; i++)
			{
				int pre_h = max(ch - abs(cx - X[i]) - abs(cy - Y[i]), 0);
				if (pre_h != H[i])
				{
					break;
				}
				else if (i == N - 1)
				{
					cout << cx << " " << cy << " " << ch;
					return 0;
				}

			}



		}
	}

	


}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Mod 1000000000 + 7
#define Maxn 1000000 + 100
typedef long long ll;
using namespace std;
bool cmp(int x,int y)
{
    return x < y;
}

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

ll quick_mod()
{
    return 0;
}
string S;
int a,b;
bool f;
int main()
{
    cin>>a>>b;
    cin>>S;
    f = true;
    for (int i = 0; i < S.size(); i++)
        if(i == a && S[a] != '-')
        {
            f = false;
            break;
        }
        else
            if( (S[i] < '0' || S[i] > '9') && i != a )
            {
                f = false;
                break;
            }
    if(!f)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int w,h,n,k,l,max;
  scanf("%d%d%d",&w,&h,&n);
  w>h?max=w:max=h;
  k=n/max;
  l=n%max;
  if(l==0)printf("%d\n",k);
  else printf("%d\n",k+1);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	string s;
	cin >> s;
	if(s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

const int N = 110;
const int Inf = 1e9;

int n, m;
char A[N][N];
int Dp[N][N][2];

int Rec(int i = 0, int j = 0, bool Last = false)
{
    int Res = (!Last && A[i][j] == '#');

    if(i == n - 1 && j == m - 1)    return Res;

    if(Dp[i][j][Last] + 1)  return Dp[i][j][Last];

    int Res1 = (i + 1 < n ? Rec(i + 1, j, (A[i][j] == '#')) : Inf);
    int Res2 = (j + 1 < m ? Rec(i, j + 1, (A[i][j] == '#')) : Inf);

    Res += min(Res1, Res2);

    return Dp[i][j][Last] = Res;
}

int main()
{
    memset(Dp, -1, sizeof(Dp));

    cin >> n >> m;

    for(int i = 0; i < n; i++)  scanf("%s", A[i]);

    cout << Rec() << endl;
}

Measured memory_bytes: 384
#include<cmath>
#include<ctime>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include <cstdio>
using namespace std;
const int N = 200001;
int b[N][2][2];
int n, ans;
bool f[N];
vector<int>g[N];
void dfs(int x, int fa)
{

    for (auto u : g[x])
        if (u != fa)
        {
            dfs(u, x);
            if (b[u][0][1] + 1 >= b[x][0][1])
            {
                b[x][1][0] = b[x][0][0];
                b[x][1][1] = b[x][0][1];
                b[x][0][0] = u;
                b[x][0][1] = b[u][0][1] + 1;
            } else
                if (b[u][0][1] + 1 > b[x][1][1])
                {
                    b[x][1][1] = b[u][0][1] + 1;
                    b[x][1][0] = u;
                }
        }
}
void dfs(int x, int fa, int len)
{
    ans = max(ans, max(b[x][1][1], len) + b[x][0][1]);
    for (auto u : g[x])
        if (u != fa)
        {
            if (b[x][0][0] != u)
                dfs(u, x, max(len + 1, b[x][0][1] + 1));
            else    dfs(u, x, max(len + 1, b[x][1][1] + 1));
        }
}
int main(){
    scanf("%d", &n);
    for (int i = 1; i < n ; i ++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1, 0);
    dfs(1, 0, 0);
    ans ++;
    f[1] = 1;
    for (int i = 3; i <= ans; i ++)
        if (!f[i - 1] || !f[i - 2])
            f[i] = 1;
    if (f[ans])
        printf("First");
    else
        printf("Second");
    return 0;
}

Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define ll long long
#define pb push_back
#define gcd __gcd

#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)


const int maxn = 2e5+100;

int Log[maxn], dp[2][20][maxn],pos[maxn],a[maxn],n;

int rmq(int k, int l, int r){
    int p = Log[r-l+1];
    return min(dp[k][p][l], dp[k][p][r-(1<<p)+1]);
}

pair<int,int> cal(int l, int r) {
    int x=rmq(l&1, l ,r);
    //倒着贪心的，所以只能在同一段
    int y=rmq((pos[x]+1)&1, pos[x]+1, r);///hhhh
    return {-x, -y};
}

typedef pair<int,int> P;
typedef pair<P, P> PP;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        pos[a[i]]=i;
    }
    for(int i=2;i<=n;i++){
        Log[i]=Log[i>>1]+1;
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            dp[i][0][j]=(j%2==i)?a[j]:(1<<30);
        }
        for(int j=1;1<<j<=n;j++){///hhh
            for(int k=0;k+(1<<j)-1<n;k++){
                dp[i][j][k]=min(dp[i][j-1][k], dp[i][j-1][k+(1<<j-1)]);
            }
        }
    }

    priority_queue<PP> Q;
    Q.push({cal(0, n-1), {0, n-1}});

    while(!Q.empty()) {
        PP it = Q.top();Q.pop();
        int x=it.first.first;
        int y=it.first.second;
        printf("%d %d ", -x, -y);
        int l=it.second.first;
        int r=it.second.second;
        x = pos[-x];
        y = pos[-y];
        if(x-1>l){
            Q.push({cal(l,x-1), {l,x-1}});
        }
        if(y+1<r) {
            Q.push({cal(y+1, r), {y+1, r}});
        }
        if(x+1 < y-1) {
            Q.push({cal(x+1, y-1), {x+1, y-1}});
        }
    }
    return 0;
}



Measured memory_bytes: 35828
#include <iostream>
#include <cstdio>

const int N = 1e2 + 3 ;

int n , v[N] , ans ;

int main () {
  	std::cin >> n ;
  	for (int i = 1 ; i <= n ; ++ i) std::cin >> v[i] ;
  	for (int i = 1 ; i <= n ; ++ i)
      	for (int j = i + 1 ; j <= n ; ++ j)
          	ans += v[i] * v[j] ;
  	std::cout << ans << "\n" ;
  	return 0 ;
}

Measured memory_bytes: 256
#coding:utf-8
K, A , B = map(int,input().split())
n = 1
if  A >= B:
    print (K+n)
elif K <=  A:
    print (K+n)
else:
    K -= (A-1)
    n += (A-1)
    if (B-A) > 2:
        n += int(K/2)*(B-A) + K % 2
    else:
        n += K
    print (n)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  long long k;
  cin >> n >> m >> k;
  vector<long long> a(n),b(m);
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<m; i++) cin >> b[i];
  int p=0;
  int q=0;
  int ans = 0;
  long long t=0;
  for(int i=0; i<n; i++){
    if(t + a[i] <= k) {
      t += a[i];
      p = i+1;
    }
    else break;
  }
  while(q<m && t+b[q]<=k){
    t += b[q];
    q++;
  }
  ans = p+q;
  while(p>0){
    p--;
    t -= a[p];
    while(q<m && t+b[q]<=k){
      t += b[q];
      q++;
    }
    ans = max(ans,p+q);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6328
#include <iostream>
using namespace std;
int main(int argc, char** argv){
	string str = "";
	cin >> str;
	for(int i=0; i< str.size(); i++){
		if(str[i] == 'h' && str[i+1] == 'i')
			i++;
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

#define EQ(a,b) (abs((a)-(b)) < EPS*10)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<P,D> C;

const D EPS = 1e-8;
const D PI = acos(-1);
inline D arg(D a,D b,D c){return acos( (b*b+c*c-a*a)/(2*b*c) );}

inline D area_cir(C c){return PI * c.sc * c.sc;}

inline D intersection_area(C a, C b){
  D d = abs(a.fs-b.fs);
  if(a.sc + b.sc < d + EPS)return 0;
  if(a.sc < b.sc)swap(a,b);
  if(b.sc + d  < a.sc + EPS || b.sc < EPS)return area_cir(b);

  D t1 = arg(b.sc,a.sc,d), t2 = arg(a.sc,b.sc,d);
  D tri = ( a.sc*a.sc*sin(t1*2) + b.sc*b.sc*sin(t2*2) )/2.0;
  return a.sc*a.sc*t1 + b.sc*b.sc*t2 - tri;
}

int main(){
  D w,h,A,B,AB;
  cout << fixed << setprecision(9);
  while(cin >> w >> h >> A >> B >> AB, w!=0){

    D ar = sqrt(A/PI), br = sqrt(B/PI);
    bool change = ar<br;
    if(change){
      swap(ar,br);
    }

    C a = C(P(ar,ar),ar), b;
    
    P l = P(br,br), r = P(w-br,h-br);
    for(int azu=0;azu<300;azu++){
      P m = 0.5L*(l+r);
      b = C(m,br);
      if(intersection_area(a,b) < AB - EPS)r = m;
      else l = m;
    }

    b = C(l,br);
    if(w+EPS<ar*2 || h+EPS<ar*2 || l.real()-br<-EPS || l.imag()-br<-EPS || w+EPS<l.real()+br || h+EPS<l.imag()+br){
      cout << "impossible" << endl;
    }else if(!EQ(intersection_area(a,b),AB)){
      cout << "impossible" << endl;
    }else{
      if(change){
	swap(a,b);
      }

      cout << a.fs.real() << " " << a.fs.imag() << " " << a.sc << " "
	   << b.fs.real() << " " << b.fs.imag() << " " << b.sc << endl;
    }
  }
}

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



int main(){
    ll n;
    ll a, b;
    cin >> n >> a >> b;
    ll num = n/(a+b);
    ll amari = n%(a+b);
    ll ans = num*a+min(amari, a);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 572
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

x=inp()
a=inp()
b=inp()
x-=a
print(x%b)


Measured memory_bytes: 3572
N, K = map(int, input().split())
S = input()

ans = 0
for x,y in zip(S, S[1:]):
    if x == y: #同じ方向を見ているとき
        ans += 1
#最大K回まで操作をして、そのたびに幸福な人が二人増える。全員同じ方向を向くとN-1
ans = N-1 if ans+2*K >= N-1 else ans+2*K
print(ans)




Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
	int x, y, z;
	scanf("%d %d", &x, &y);
	while (x != 0 || y != 0){
		
		if (x > y){ z = x; x = y; y = z;
	}
		printf("%d %d\n", x, y);
		scanf("%d %d", &x, &y);
	} 

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main() {
  int i;

  // initialize lines
  int w;
  scanf("%d", &w);
  int lines[w];
  for (i = 0; i < w; i++) {
    lines[i] = i + 1;
  }

  // swapping
  int n;
  int a, b;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d,%d", &a, &b);
    swap(&lines[a - 1], &lines[b - 1]);
  }

  // printing
  for (i = 0; i < w; i++) {
    printf("%d\n", lines[i]);
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    long MOD = (long)1e9 + 7;

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = " " + sc.next();
        int n = s.length() - 1;
        int[][] dp = new int[n + 1][13];
        dp[0][0] = 1;

        for (int i = 1; i <= n; i++) {
            if (s.charAt(i) == '?') {
                for (int j = 0; j < 13; j++) {
                    for (int k = 0; k < 10; k++) {
                        int r = (j * 10 + k) % 13;
                        dp[i][r] += dp[i - 1][j];
                        dp[i][r] %= MOD;
                    }
                }
            } else {
                int digit = s.charAt(i) - '0';
                for (int j = 0; j < 13; j++) {
                    int r = (j * 10 + digit) % 13;
                    dp[i][r] += dp[i - 1][j];
                    dp[i][r] %= MOD;
                }
            }
//            debug(dp[rev]);
        }

        System.out.println(dp[n][5]);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 34148
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e9
#define eps 1e-6
#define PI acos(-1.0)
#define M 10010
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

string s;
ll k;
ll d = 5e15;

ll poww(ll x,ll n)
{
    ll res=1;
  while(n>0)
  {
     if(n%2==1) 
     {
       res=res*x;
       if(res>=k)
        return k;
     }
     x=x*x;
     n>>=1;
  }
  return res; 
}

int main() {
  //freopen("in.txt", "r", stdin);
  //freopen("out.txt","w",stdout);
  cin >> s >> k;
  ll num = 0;
  for(int i = 0; i < s.length(); ++i)
  {
      ll v = s[i] - '0';
      if(v == 1) num += 1;
      else num += k;
      if(num >= k) {
         cout << v <<endl;
         return 0;
      }
      //cout << num <<endl;
  }
  return 0;
}

Measured memory_bytes: 256