akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
using namespace std;

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// すべてのaの__builtin_ctzを合計する

int main() {
  int n;cin>>n;
  int ans = 0;
  rep(i,n) {
    int a;cin>>a;
    ans += __builtin_ctz(a);
  }
  cout << ans << endl;
}


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

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a.begin(),a.end());
    ll ans = 0, drink = 0;
    for(int i=0;i<n;i++){
        if(drink + a[i].second <= m){
            ans += a[i].first * a[i].second;
            drink += a[i].second;
        }
        else{
            while(drink < m){
                ans += a[i].first;
                drink++;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4804
L = list(map(int, input().split()))
L.sort()

ans = 0
ans += L[2]-L[1]
L[0] += L[2]-L[1]
L[1] = L[2]

if (L[2]-L[0])%2 == 0:
    ans += (L[2]-L[0])//2
else:
    ans += 1+(L[2]+1-L[0])//2

print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,s;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<vi> v(n,vi(n+1));
    rep(i,n)rep(j,n+1)cin>>v[i][j];
    vi dp(1<<n,INF);
    dp[0]=0;
    rep(s,(1<<n)){
      rep(i,n)if((s&(1<<i))==0){//iテ」ツつ津ヲツ板サテァツ閉・
	int tmp=v[i][0];
	rep(j,n)if((s&(1<<j))!=0)//jテ」ツつ津ヲツ板サテァツ閉・テヲツクツ暗」ツ?ソ
	  tmp=min(tmp,v[i][j+1]);
       	dp[s|(1<<i)]=min(dp[s|(1<<i)],dp[s]+tmp);
      }
    }
    cout<<dp[(1<<n)-1]<<endl;
  }
}

Measured memory_bytes: 3284
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define Pd (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++){cin>>a[i];}
	for(int i=0;i<min(k,50);i++){
		vector<int>b(n+1,0);
		for(int j=0;j<n;j++){
			int l = max(0,j-a[j]);
			int r = min(n,j+a[j]+1);
			b[l]++;b[r]--;
		}
		for(int i=1;i<n;i++)b[i]+=b[i-1];
		a = b;
	}
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char x,y;
	cin>>x>>y;
	if (x<y)
	 cout<<"<"<<endl;
	if (x>y)
	 cout<<">"<<endl;
	if (x==y)
	 cout<<"="<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

D = int(input())
c = np.array(list(map(int,input().split())))
s = np.array([list(map(int,input().split())) for _ in range(D)])

last = np.zeros(26,int)

score = 0

for i in range(D):
    
    last += 1
    each_s_minus = c*last
    
    score -= each_s_minus.sum()
    
    each_score = s[i,:] + each_s_minus
    
    t = np.argmax(each_score)
    
    score += each_score[t]
    
    last[t] = 0
    
    print(t+1)

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

int main() {
    int n, m;
    cin >> n >> m;
    int h[n];
    rep(i, n) cin >> h[i];
    vector<int> v[n];

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int ans = 0;
    rep(i, n) {
        bool ok = true;
        for (auto c : v[i])
            if (h[c] >= h[i]) ok = false;
        if (ok) ans++;
    }

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


Measured memory_bytes: 9132
package main
import (
	"fmt"
	"bufio"
	"os"
	"bytes"
	"strconv"
	"strings"
)

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num , _ :=  strconv.Atoi(scanner.Text())
	return num
}


func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	N := nextInt(scanner)
	var A [][]int = make([][]int, N)
	for i:=0; i<N; i++ {
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		idx := nextInt(scanner)
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			node := nextInt(scanner)
			A[idx-1][node-1] = 1
		}
	}
	var outBuffer bytes.Buffer
	for i:=0; i<N; i++ {
		outBuffer.WriteString(strings.TrimRight(fmt.Sprintf("%v",A[i])[1:], "]") + "\n")
	}
	fmt.Printf("%s", outBuffer.String())
}


Measured memory_bytes: 1448
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,l; cin >> n >> l;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  rep(i,n-1) {
    if(a[i] + a[i+1] >= l) {
      cout << "Possible" << "\n";
      rep(j,i) {
	cout << j+1 << "\n";
      }
      for (int j = n-1; j >= i + 2; --j) {
	cout << j << "\n";
      }
      cout << i+1 << "\n";
      return 0;
    }
  }
  cout << "Impossible" << "\n";

  
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  cout<<((C>=A and C<=B)?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
($a[$_],$b[$_],$c[$_])=glob<>for 1..<>;map{$x=0;$x=($x<$b[$_]?$b[$_]:(~-$x/$c[$_]+1|0)*$c[$_])+$a[$_]for$_..@a-2;print$x,$/}1..$#a

Measured memory_bytes: 1024
import numpy as np

N, Q = map(int, input().split())  # 複数数値入力
S = list(input())  # 一文字ずつ格納

dp = [0] * N
i = 0
flg = False
for str in S:
    if str == "C" and flg == True:
        dp[i] = dp[i - 1] + 1
        flg = False
    elif str == "A":
        flg = True
        dp[i] = dp[i-1]
    else:
        flg = False
        dp[i] = dp[i-1]
    i += 1

for i in range(Q):
    l, r = map(int, input().split())  # 複数数値入力
    print(dp[r-1]-dp[l-1])


Measured memory_bytes: 16316
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll 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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll n;
mint dp[1000010];

int main() {
  std::cin >> n;

  mint dpS = 0;

  dp[1] = n;
  dp[2] = n*n;

  dpS = dp[1]+dp[2];

  repi( k, 3, n+1 ) {
    dp[k] = dpS-dp[k-2]+mint(n-1).pow(2)+n-k+2;
    dpS += dp[k];
  }

  std::cout << dp[n].x << endl;

  return 0;
}

Measured memory_bytes: 11456
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>

using namespace std;

#define fi first	
#define se second
#define long long long
typedef pair<int,int> ii;

int depth;
vector<ii> vec;

int curr = 2;

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	string s; cin >> s;
	int n = s.size();
	s = '0' + s ;
	
	if(s[n] == '1' || s[1] == '0' || s[n-1] == '0')
	{
		printf("-1\n");
		return 0;
	}

	for(int i = 1; i <= n/2; i++)
	{
		if(s[i] != s[n-i])
		{
			printf("-1\n");
			return 0;
		}
		if(s[i] == '1')
			depth = i;
	}
	
	int ROOT = 1;
	for(int i = 1; i < depth; i++)
	{
		if(s[i] == '1')
		{
			vec.push_back({curr,ROOT});
			ROOT = curr;
			++curr;
		}
		else
		{
			vec.push_back({curr,ROOT});
			++curr;
		}
	}
	int root2 = curr;
	vec.push_back({ROOT, curr});
	while(curr < n)
		vec.push_back({root2, ++curr});

	// printf("ROOT : %d\n", ROOT);
	for(auto it : vec) printf("%d %d\n", it.fi, it.se);
}





Measured memory_bytes: 2416
/**
* Copyright(c)
* All rights reserved.
* Author : zzy
* Date : 2020-04-12-20.01.59
*/
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <iterator>
#include <list>
#include <cstdio>
#include <iomanip>
#include <climits>

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

using namespace std;

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

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

i64 n;
i64 ans = 0;

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

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << '\n';

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


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b; cin >> a >> b;
	int d = b - a;
	int ans = d * (d-1) / 2 - a;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
from collections import deque
N,M = map(int,input().split())
link = [ [] for _ in range(N+1)]
value = [ -1 for _ in range(N+1)]

for _ in range(M):
  L,R,D = map(int,input().split())
  link[L].append((R,D))
  link[R].append((L,-D))

searched = set()
queue = deque()
for u in range(N+1):
  if u not in searched:
    queue.append(u)
    searched.add(u)
    value[u] = 0
    while queue:
      v = queue.popleft()
      for w,d in link[v]:
        if w not in searched:
          value[w] = value[v] + d
          queue.append(w)
          searched.add(w)

#verification
for v in range(N+1):
  for w,d in link[v]:
    if value[w] != value[v] + d:
      print("No")
      exit()
print("Yes")
      

Measured memory_bytes: 72012
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll dp[2001][2001];
int main() {
	cin >> N;
	pair<ll, ll> arr[2000];
	ll active, ans = 0;
	rep(i, N) {
		cin >> active;
		arr[i] = make_pair(active, i + 1);
	}
	sort(arr, arr + N);
	reverse(arr, arr + N);
	ll front_index = 1, back_index = N;
	ll scoremax = 0;
	dp[0][0] = 0;
	for (ll x = 0, y = 0; x < N; x = y, y = 0) {
		auto curr = arr[x + y];
		for (; x >= 0; x--, y++) {
			dp[y][x + 1] = max(dp[y][x + 1], dp[y][x] + arr[x + y].first * abs(arr[x + y].second - x - 1));
			dp[y + 1][x] = max(dp[y + 1][x], dp[y][x] + arr[x + y].first * abs(N - y - arr[x + y].second));
		}
	}
	rep(i, 2001) {
		rep(j, 2001) {
			scoremax = max(scoremax, dp[i][j]);
		}
	}
	cout << scoremax;
}

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

signed main() {
  int x; cin>>x;
  if(400<=x && x<=599)
    cout<<8<<endl;
  else if(600<=x && x<=799)
    cout<<7<<endl;
  else if(800<=x && x<=999)
    cout<<6<<endl;
  else if(1000<=x && x<=1199)
    cout<<5<<endl;
  else if(1200<=x && x<=1399)
    cout<<4<<endl;
  else if(1400<=x && x<=1599)
    cout<<3<<endl;
  else if(1600<=x && x<=1799)
    cout<<2<<endl;
  else if(1800<=x && x<=1999)
    cout<<1<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define INF 9223372036854775807
const ll mod=1e9+7;


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

    ll n,k;
    cin>>n>>k;
    vector<ll> a(n+1);
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    vector<ll> b;
    map<ll,ll> c;
    ll pos=1,h=0;
    while(c.find(pos)==c.end()){
        c[pos]=h++;
        b.pb(pos);
        pos=a[pos];
    }
    if(k<c[pos]){
        cout<<b[k];
        return 0;
    }
    k-=c[pos];
    vector<ll> d;
    for(ll i=c[pos];i<b.size();i++)
        d.pb(b[i]);
    //for(ll i=0;i<b.size();i++)
    //    cout<<b[i]<<" ";
    ll r=d.size();
    ll p=k%r;
    cout<<d[p];


    return 0;
}


Measured memory_bytes: 18980
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    Yes(a<b&&b<c);

    return 0;
}



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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

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

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    vector< pair< int, int > > ps(n);
    for (auto &p: ps) cin >> p;

    i64 l, r;

    whole(sort, ps);
    l = ps[n / 2].first;
    if ((n & 1) == 0) l += ps[n / 2 - 1].first;

    whole(sort, ps, [&](auto a, auto b) { return a.second < b.second; });
    r = ps[n / 2].second;
    if ((n & 1) == 0) r += ps[n / 2 - 1].second;

    cout << r - l + 1 << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 4784
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vvl out(N); vl incnt(N, 0);
    REP(i, N-1+M){
        ll a, b; cin >> a >> b; a--; b--;
        out[a].pb(b);
        incnt[b]++;
    }
    
    vl root(N, -LINF);
    stack<ll> st;
    REP(i, N){
        if(incnt[i] == 0){
            st.push(i); root[i] = -1;
        }
    }
    
    vl ans;
    while (!st.empty()) {
        ll now = st.top(); st.pop();
        ans.pb(now);
        for(ll to : out[now]){
            incnt[to]--;
            if(incnt[to] == 0){
                st.push(to);
                root[to] = now;
            }
        }
    }
    
    REP(i, N){
        cout << root[i]+1 << endstr;
    }
    return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

// const ll mod = 1000000007;
const ll mod = 998244353;

const int MAX_N = 10000010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void generate_table(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n;
    cin >> n;
    generate_table(n);
    vector<ll> pow2(n+1,1);
    for (int i = 0;i < n;++i) pow2[i+1] = pow2[i]*2%mod;
    ll ans = pow_mod(3,n);
    for (int i = 0;i < n/2;++i) {
        (ans -= combi(n,i)*pow2[i]*2%mod) %= mod;
    }
    cout << (ans+mod)%mod << endl;
}

Measured memory_bytes: 312704
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	vector<int> vec(3);
	for (auto& v : vec) {
		cin >> v;
	}

	int k;
	cin >> k;

	for (int i = 0; i < k; i++) {
		sort(begin(vec), end(vec), greater<ll>());
		vec[0] *= 2LL;
	}

	cout << accumulate(begin(vec), end(vec), 0LL) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}
ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int M=in();
    if(M==0){
        if(N==1){
            cout<<0<<endl;
            return 0;
        }else{
            cout<<pow(10,N-1)<<endl;
            return 0;
        }
    }
    int ans=1000;
    vector<pair<int,int>> p;
    REP(i,M){
        int s;int c;
        if(s==1&&c==0){
            ans=-1;
        }else{
        cin>>s>>c;
        p.pb(mp(s,c));
        }
    }
    if(ans<1000){
        cout<<ans<<endl;
        return 0;
    }
    int start;
    if(N==1){
        start=0;
    }else{
        start=pow(10,N-1);
    }
    for(int i=start;i<pow(10,N);i++){
        int d[N+1];
        REP1(j,N){
            int a=pow(10,j);
            d[N-j+1]=(i%a)/pow(10,j-1);
        }
        REP(j,p.size()){
            if(d[p[j].first]!=p[j].second){
                break;
            }else{
                if(j==p.size()-1){
                    cout<<i<<endl;
                    return 0;
                }
            }
        }

    }
    cout<<-1<<endl;
        return 0;
}


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

int main(){
    int n, w_limit;
    cin >> n >> w_limit;
    vector<int> v(n);//品物の価値
    vector<int> w(n);//品物の重さ
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];
    
    vector<vector<int> > memo(n+1, vector<int>(w_limit+1, 0));
    /*
    動的計画法の表
    memo[i+1][j] = i番目までの品物を重さj以下になるように選んだときの
    品物の価値の和
    */
    
    //for(int i = 0; i <= w_limit; i++) memo[0][i] = 0;//memo[0][i]は品物を何も選んでいないときの品物の価値の和　よって0
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w_limit; j++){
            if(j - w[i] >= 0){//i番目の品物を追加しても重さがj以下に収まるとき
                memo[i+1][j] = max(memo[i][j], memo[i+1][j-w[i]]+v[i]);
                //i番目の品物を追加しない or 追加する
            }else{
                memo[i+1][j] = memo[i][j];
            }
        }
    }
    //n-1番目（最後）までの品物を重さw_limit以下になるように選んだときの品物の価値の和を出力
    cout << memo[n][w_limit] << endl;
    return 0;
}
    


Measured memory_bytes: 6744
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll x; cin>>x;
    ll ans=(x/500)*1000;
    ans+=(x-x/500*500)/5*5;

    
    cout<<ans<<endl;
}
 



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

int main(){
    int N; cin >> N;
    vector<int> v;
    int cnt4=0, cnt2=0;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        if(a%4==0) cnt4++;
        if(a%2==0&&a%4!=0) cnt2++;
    }
    if(cnt2/2+cnt4>=N/2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n, a[100000], k,ans;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	ans = 1 + ((n - k) / (k - 1)) + ((n - k) % (k - 1) == 0 ? 0 : 1);
	cout << ans  <<endl;
	return 0;
}

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

ll num(const vector<ll> &v, ll low, ll up, ll a){
    ll left = lower_bound(v.begin(), v.end(), low - a) - v.begin();
    ll right = lower_bound(v.begin(), v.end(), up - a) - v.begin();
    return right - left;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N), b(N);
    for(ll &i : a) cin >> i;
    for(ll &i : b) cin >> i;
    ll ans = 0;
    for(ll i = 0; i <= 28; i++){
        ll cnt = 0;
        vector<ll> tmp;
        for(ll u : b) tmp.push_back(u % (1 << (i + 1)));
        sort(tmp.begin(), tmp.end());
        for(ll u : a){
            u %= (1 << (i + 1));
            cnt += num(tmp, (1 << i), (1 << (i + 1)), u);
            cnt += num(tmp, (1 << (i + 1)) + (1 << i), (1 << (i + 1)) + (1 << (i + 1)), u);
        }
        if(cnt & 1) ans += (1 << i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7028
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=998244353,N=1000002;
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int INV(int x){return pw(x,M-2);}
int ans,i,a[N],t,x,n;
signed main(){
	scanf("%lld",&n);
	for (i=1;i<=n+1;i++) scanf("%lld",&a[i]);
	for (i=1;i<=n;i++){
		scanf("%lld",&x);
		t=min(x,a[i]);
		ans+=t,a[i]-=t,x-=t;
		t=min(x,a[i+1]);
		ans+=t,a[i+1]-=t,x-=t;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
n,a,b=map(int,input().split())
 
def find_sum_of_digits(n):
    sum = 0
    int(n)
    while n > 0:
        sum += n % 10
        n //= 10
    return sum
 
total = 0
for i in range(1, n+1):
    sum_of_digits_tmp = find_sum_of_digits(i)
    if a <= sum_of_digits_tmp and sum_of_digits_tmp <= b:
        total += i
 
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define NewNode (ListNode *)malloc(sizeof(ListNode))
#define Mem(a,b) memset(a,b,sizeof(a))
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const unsigned long long mod = 998244353;
const double II = 3.1415926535;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
map<int,int> mp;
int main()
{
//    std::ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
    ll ans = 0,n;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        ll a;
        cin >> a;
        ans += mp[a-i];
        mp[-1*a-i]++;
    }
    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int a[N];

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

    int rel = 0;

    while(true) {
        bool hantei = false;
        for (int i = 0; i < N; i++) {
            if (a[i] % 2 != 0) hantei = true;
        }

        if (hantei == true) break;

        for (int i = 0; i < N; i++) {
            a[i] /= 2;
        }
        rel++;
    }

    cout << rel << endl;
}

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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
  int x;
  cin >> x;
  cout << (x ^ 1);
  return 0;
}

Measured memory_bytes: 3612
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (B < C || D < A) {
        cout << 0 << endl;
        return 0;
    }
    cout << min(B, D) - max(A, C) << endl;

    return 0;
}


Measured memory_bytes: 256
h, w, n = map(int, input().split())
sh, sw = map(int, input().split())
s = input()
t = input()

d = {"L": (0, -1), "R": (0, 1), "U": (-1, 0), "D": (1, 0)}


def f(s_dir, t_dir):
    nh = sh
    nw = sw
    sdh, sdw = d[s_dir]
    tdh, tdw = d[t_dir]
    for es, et in zip(s, t):
        if es == s_dir:
            nh += sdh
            nw += sdw
            if nh < 1 or nh > h or nw < 1 or nw > w:
                return True

        if et == t_dir:
            tmph = nh + tdh
            tmpw = nw + tdw
            if 1 <= tmph <= h and 1 <= tmpw <= w:
                nh = tmph
                nw = tmpw

    return False


if f("L", "R") or f("R", "L") or f("U", "D") or f("D", "U"):
    ans = "NO"
else:
    ans = "YES"

print(ans)


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

constexpr int MAX_N = 1e5;
bool a[MAX_N+1];
int s[MAX_N+1+1];

int main() {
  // エラトステネスのふるい
  bitset<MAX_N + 1> isPrime;
  for (int i{2}; i <= MAX_N; ++i)
    isPrime.set(i);
  for (int i{2}; i <= MAX_N; ++i) {
    if (isPrime[i]) {
      for (int j{i * 2}; j <= MAX_N; j += i) {
        isPrime.reset(j);
      }
    }
  }

  for (int i{3}; i <= MAX_N; i += 2) {
    if (isPrime[i] && isPrime[(i+1)/2])
      a[i] = true;
  }

  for (int i{1}; i < MAX_N; ++i) {
    s[i+1] = s[i] + a[i];
  }

  int Q;
  cin >> Q;
  for (int i{}; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << s[r + 1] - s[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

class BIT { // index starts at 1.
public:
  int N;
  ll* data;

  BIT(int n) : N(n) {
    data = new ll[N+1];
    for (auto i = 1; i <= N; ++i) {
      data[i] = 0;
    }
  }

  ~BIT() {
    delete[] data;
  }

  ll _sum(int i) { // [1, i]
    ll s = 0;
    while (i > 0) {
      s += data[i];
      i -= i & -i;
    }
    return s;
  }
  
  void _add(int i, ll x) {
    while (i <= N) {
      data[i] += x;
      i += i & -i;
    }
  }

  ll get(int i) {
    return _sum(i);
  }

  void add(int a, int b, ll x) { // [a, b)
    _add(a, x);
    _add(b, -x);
  }
  
};

int main () {
  int n, q;
  cin >> n >> q;
  BIT bit(n);
  for (auto i = 0; i < q; ++i) {
    int com;
    cin >> com;
    if (com == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      bit.add(s, t+1, x);
    } else {
      int a;
      cin >> a;
      cout << bit.get(a) << endl;
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,a,minbox;
  cin >> n >> k;
  vector<int> ans;
  pair<int, int> p[n];
  for(int i=0;i<n;i++){
    cin >> a;
    p[i] = make_pair(a, i+1);
  }
  sort(p, p+n);
  for(int i=n-1;i>=0;i--){//大きい方から全部見る -> 必ずk-1できる
    ans.push_back(p[i].second);
    p[i].first--;
  }
  k--;
  minbox=p[0].second;
  /*
    最後に見た箱に絶対宝石はないので他の箱を全部見ると必ずk-1できる(できそう)
    これを繰り返すと良さそう？？？？
  */

  bool f=false;
  for(int i=k;i>=0;i--){
    int x;
    if(!f){//一番目に少ない箱にはない
      sort(p, p+n);
      for(int j=n-1;j>=0;j--){
        if(p[j].second!=minbox){;
          if(p[j].first == 0){
            cout << -1 << endl;
            return 0;
          }
          x=p[j].second;
          ans.push_back(p[j].second);
          p[j].first--;
        }
      }
      minbox=x;
      f=true;
    }else{//二番目に少ない箱にはない
      sort(p, p+n);
      for(int j=n-1;j>=0;j--){
        if(p[j].second!=minbox){
          if(p[j].first == 0){
            cout << -1 << endl;
            return 0;
          }
          x=p[j].second;
          ans.push_back(p[j].second);
          p[j].first--;
        }
      }
      minbox=x;
      f=false;
    }
  }
  cout << ans.size() << endl;
  for(size_t i=0;i<ans.size();i++){
    cout << ans[i] << ((i==ans.size()-1)?'\n':' ');
  }
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=2e5+5;

int st[6*N],qt[6*N],a[N],h[N];

void update_tree(int cur,int s,int e,int pos,int val)
{
     if(pos<s || pos>=e)
          return;
     if(s==pos && s==e-1)
     {
          st[cur]=val;
          return;
     }
     int c1=(cur<<1),c2=c1+1,m=(s+e)>>1;
     update_tree(c1,s,m,pos,val);
     update_tree(c2,m,e,pos,val);
     st[cur]=max(st[c1],st[c2]);
}

void query_tree(int cur,int s,int e,int l,int r)
{
     if(l>=e || r<=s)
     {
          qt[cur]=0;
          return;
     }
     if(s>=l && r>=e)
     {
          qt[cur]=st[cur];
          return;
     }
     int c1=2*cur,c2=c1+1,m=(s+e)>>1;
     query_tree(c1,s,m,l,r);
     query_tree(c2,m,e,l,r);
     qt[cur]=max(qt[c1],qt[c2]);
}

int32_t main()
{
     IOS;
     
     int n;
     cin>>n;
     for(int i=1;i<=n;i++)
          cin>>h[i];
     for(int i=1;i<=n;i++)
          cin>>a[i];
     int ans=0;     
     for(int i=1;i<=n;i++)
     {
          query_tree(1,1,n+1,1,h[i]);
          int temp=qt[1];
          temp+=a[i];
          ans=max(ans,temp);
          update_tree(1,1,n+1,h[i],temp);
     }
     cout<<ans;
     return 0;
}


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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

int main(){

  char s[100001];
  scanf("%s", s);

  int left = 0, right = strlen(s) - 1;
  int res = 0;
  while(left <= right){
    if(s[left] == s[right]){
      left++; right--;
    }else if(s[left] == 'x'){
      res++;
      left++;
    }else if(s[right] == 'x'){
      res++;
      right--;
    }else{
      printf("-1\n");
      return 0;
    }
  }

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



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

int main() {
  int a, b, c; cin >> a >> b >> c;
  if( a + b >= c )  puts("Yes");
  else puts("No");
}

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

#define int long long

signed main(){
  int n;cin>>n;
  int ans=0,pre;cin>>pre;
  for(int i=1;i<n;i++){
    int a;cin>>a;
    if(pre>a)ans+=pre-a;
    else pre=a;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") { sum += x; }
    else { sum += x * 380000; }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef unsigned long long ll;

int binarySerch(int *a, int n, int key){
	int left = 0;
	int right = n;
	while( left < right ){
		int mid = (left + right) / 2;
		if(a[mid] == key) return 1;
		else if(a[mid] < key) left = mid + 1;
		else right = mid;
	}
	return 0;
}

int main(void){
	int n;
	cin >> n;
	int s[n];
	rep(i, n) cin >> s[i];
	int q;
	cin >> q;
	int t[q];
	rep(i, q) cin >> t[i];

	int sum = 0;
	for(int i = 0; i < q; i++){
		if(binarySerch(s, n, t[i])) {
			sum++;
		}
	}
	cout << sum << endl;
}



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int a=in.nextInt(),sum,min=Integer.MAX_VALUE;
        int A[]=new int[a];
        for(int i=0;i<a;i++)
            A[i]=in.nextInt();
        for(int j=0;j<101;j++) {
            sum=0;
            for (int i = 0; i < a; i++) {
                sum +=(A[i]-j)*(A[i]-j);
            }
            min=Math.min(sum,min);
        }
        System.out.println(min);

    }
}


Measured memory_bytes: 23764
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val h = (0 until n).map {
        sc.next().toLong()
    }

    println(abc153c(k, h))
}

fun abc153c(k: Int, h: List<Long>): Long {
    var hs = h.sorted().reversed()
    var ans = 0L
    for (i in 0..hs.size - 1) {
        if (i < k) {
           continue 
        }
        ans += hs.get(i)
    }

    return ans
}

Measured memory_bytes: 62152
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll A,B,C,D;
  cin>>A>>B>>C>>D;
  ll m=min(A,B);
  ll n=min(C,D);
  cout<<m+n<<endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 55440;

int cnt[MAX_N+1];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        rep(i,MAX_N){
            cnt[i] = 0;
        }
        vvi vec(25);
        rep(i,25){
            vec[i].resize(i,0);
        }
        rep(i,n){
            int d,t;
            cin >> d >> t;
            rep(j,d){
                int a;
                cin >> a;
                vec[d][(t+d-j)%d] += a;
            }
        }
        int ans = 0;
        srep(i,1,25){
            if(MAX_N % i == 0){
                rep(j,MAX_N){
                    cnt[j] += vec[i][j%i];
                }
            }else{
                int mx = 0;
                rep(j,i){
                    cmx(mx,vec[i][j]);
                }
                ans += mx;
            }
        }
        int res = 0;
        rep(i,MAX_N){
            cmx(res,cnt[i]);
        }
        cout << ans + res << "\n";
    }
    return 0;
}



Measured memory_bytes: 3364
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  ll a = 0;
  for(ll i = n; i > 0; i/=10){
    a += i%10;
  }
  if(n%a==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256