akhauriyash/Code-Regression huggingface dataset:
/*
    Problem 100
    https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N; cin >> N;
    ll K = 1;
    bool exist = false;
    for (; K <= N; K++) {
        if (K* (K+1)/2 == N) {
            exist = true;
            break;
        }
    }
    if (!exist) cout << "No" << '\n';
    else {
        cout << "Yes" << '\n';
        cout << K+1 << '\n';
        vector<vector<ll>> res(K+1, vector<ll>());
        ll sum = 1;
        for (int k = K; k >= 1; k--) {
            for (int i = 0; i < k; i++) {
                res[K-k].push_back(sum+i);
                res[K-k+i+1].push_back(sum+i);
            }
            sum += k;
        }

        for (int i = 0; i < K+1; i++) {
            cout << res[i].size();
            for (int j = 0; j < res[i].size(); j++)
                cout << " " << res[i][j];
            cout << '\n';
        }
    }
}

Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
int diff(string &s, string& t) {
    int n = s.length();
    int cnt = 0;
    for (int i= 0; i < n; i++) {
        cnt += s[i] != t[i];
    }
    return cnt;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int red = count(s.begin(), s.end(), 'R');
    int ans = 0;
    for (int i = 0; i < red; i++) {
        ans += s[i] != 'R';
    }
    cout << ans;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;
int sheet[3][3];

int main(){
    int a[3][3];
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    rep(i,n){
        int tmp; cin>>tmp;
        rep(j,3){
            rep(k,3){
                if(a[j][k]==tmp) sheet[j][k]=1;
            }
        }
    }
    rep(i,3){
        if(sheet[i][0]==1&&sheet[i][1]==1&&sheet[i][2]==1){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(sheet[0][i]==1&&sheet[1][i]==1&&sheet[2][i]==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(sheet[0][0]==1&&sheet[1][1]==1&&sheet[2][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(sheet[0][2]==1&&sheet[1][1]==1&&sheet[2][0]==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
def bsearch(mn, mx, func):
    #func(i)=False を満たす最大のi
    idx = (mx + mn)//2
    while mx-mn>1:
        if func(idx):
            idx, mx = (idx + mn)//2, idx
            continue
        idx, mn = (idx + mx)//2, idx
    return idx
N, = map(int, input().split())
A = list(map(int, input().split()))
X = [0]*(N+2)
for i in range(N):
    X[i+1] = X[i] + A[i]

R = 10**18
for i in range(2, N-1):
    # X0, X1, X2 .. Xi
    # Xj Xj+1 (1<= j <= i-1)
    idx1 = bsearch(1, i-1, lambda j:X[i]//2 < X[j])
    idx2 = bsearch(i+1, N, lambda j:(X[N]-X[i])//2 < (X[j]-X[i]))
#    print(X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2])
    if idx1+1 <= i-1:
        if abs(2*X[idx1]-X[i]) > abs(2*X[idx1+1]-X[i]):
            idx1+=1
#    print(1,i,idx2)
    if idx2+1 <= N-1:
        if abs(2*X[idx2]-X[i]-X[N]) > abs(2*X[idx2+1]-X[i]-X[N]):
            idx2+=1
    mx = max([X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2]])
    mn = min([X[idx1], X[i]-X[idx1], X[idx2]-X[i], X[N]-X[idx2]])
#    print(X[i]-X[idx1], X[idx1], X[idx2]-X[i])
#    print(idx1, i, idx2)
#    print(mx-mn)
    R = min(R, mx-mn)
print(R)



Measured memory_bytes: 105464
N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if i+1 == P[i]:
        ans += 1
        P[i], P[i+1] = P[i+1], P[i]

if N == P[-1]:
    ans += 1

print(ans)

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

int main() {
  string S;
  int N, M;
  cin >> N >> S;
  
  M = 0;
  
  for (int i = 0; i < N-2; i++) {
    if ( S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2)== 'C' ) {
    M = M+1;
    }
  }
    
  cout << M << endl;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
int a[10];
bool dfs(int k,int B,int C)
{
    if(k==10)
        return true;
    if(a[k]>B)
    {
        if(dfs(k+1,a[k],C))
            return true;
    }
    if(a[k]>C)
    {
        if(dfs(k+1,B,a[k]))
            return true;
    }
    return false;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        for(int i=0;i<10;i++)
            cin>>a[i];
        if(dfs(0,0,0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1116
#include<iostream>
#include<algorithm>          //常用函数库，标准模版库STL头文件之一 
using namespace std;
struct student
{
	int num;
	int total;
} s[100100];          //用结构体数组可使每个元素具有多个属性 
bool cmp(student a,student b)
{
	return a.total<b.total;          //按total大小升序排序 
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		s[i].num=i;
		cin>>s[i].total;
	}
	sort(s+1,s+1+n,cmp);          //void sort(起始地址,结束地址,排序方式);
	for(int i=1;i<=n;i++)
	{
		if(i!=n) cout<<s[i].num<<" ";
		else cout<<s[i].num;          //输出最后一个数时其后不带空格 
	}
}

Measured memory_bytes: 3884
# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]
n = int(input())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

p = [] #点p
edge = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i])
p.sort(key=lambda x:x[0])
for i in range(n-1):
    x_0,_,j=p[i]
    x_1,_,k=p[i+1]
    edge.append([x_1-x_0,j,k]) # 重みx_1 - x_0の点jと点kを繋ぐ辺
p.sort(key=lambda x:x[1])
for i in range(n-1):
    _,y_0,j=p[i]
    _,y_1,k=p[i+1]
    edge.append([y_1-y_0,j,k])

edge.sort() #クラスカル法を使うので重みでソート
ans = 0
for i in range(len(edge)):
    cost,u,v = edge[i]
    if not same(u,v):
        unite(u,v)
        ans+=cost
print(ans)

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

using namespace std;
const int Mod=1e9+7;
typedef long long LL;
LL n;

LL qsm(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return ans;
}

int main()
{
	int i;
	scanf("%lld",&n);
	printf("%lld",((qsm(10ll,n)-qsm(9ll,n)+Mod)-qsm(9ll,n)+Mod+qsm(8ll,n)%Mod)%Mod);
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
long long int N, Ans = 0, total = 0;cin >> N;
map<long long int, long long int> P;
map<long long int, long long int> Q;
vector<long int> V(N);

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

for(auto i : P)
total += ( P[i.first]*(P[i.first] - 1) )/2;


    for(auto i : P)
    Q[i.first] = total - ( P[i.first]*(P[i.first] - 1) )/2 + ( (P[i.first] - 1)*(P[i.first] - 2) )/2;
    

for(auto i : V)cout << Q[i] << endl;

}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  string s;
  Solver(LL n) : n(n){};

  void solve() {
    cin >> s;
    string l, r;
    l = s.substr(0, n);
    r = s.substr(n);
    reverse(r.begin(), r.end());
    DBG(l, r)
    LL ans = 0;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
      string s1 = "", s2 = "";

      for (int j = 0; j < n; ++j) {
        if ((i >> j) & 1)
          s1.push_back(l[j]);
        else
          s2.push_back(l[j]);
      }
      vector<vector<LL>> dp(s1.size() + 1, vector<LL>(s2.size() + 1));
      dp[0][0] = 1;
      for (int j = 1; j <= n; ++j) {
        for (int k = 0; k <= s1.size(); ++k) {
          //j文字目まで、　s１をk文字、s2をj-k文字
          if (j - k < 0 or s2.size() < j - k) continue;
          if (k >= 1 and s1[k - 1] == r[j - 1]) dp[k][j - k] += dp[k - 1][j - k];
          if (j - k >= 1 and s2[(j - k) - 1] == r[j - 1]) dp[k][j - k] += dp[k][j - k - 1];
        }
      }
      ans += dp[s1.size()][s2.size()];
    }
    ans *= 2;
    cout << ans << "\n";
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(K)]
LR.sort()
mod = 998244353
ma = [0] * N
ma[0] = 1
for i in range(N):
    if i >1:
        ma[i] += ma[i-1]
    p = ma[i]%mod
    if p != 0:
        for l,r in LR:
            if i+l <N:
                ma[i+l] += p
            else:
                break
            if i+r+1<N:
                ma[i+r+1] -= p
print(ma[N-1]%mod)

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

#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 0; (int)(n) < i; i--)
#define Int long long
using namespace std;

int main(void){
    string a,b;
    int c = 0;
    cin >> a;
    cin >> b;
    for(int i = 0; i<a.size();i++){
        for(int j = 0; i<b.size();i++){
            if(a[i] != b[i]){
                c++;
            }
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3860
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        //MaximumProfit.solve();

        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] a = Arrays.stream(scanner.nextLine().split(" ", 0))
                .mapToInt(Integer::parseInt)
                .toArray();

        int[] sortedA = insertionSort(a, n);
        printIntArray(sortedA, " ");
    }

    private static int[] insertionSort(int[] a, int length) {
        for (int i = 1; i < length; i++) {
            printIntArray(a, " ");
            int v = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > v) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = v;
        }
        return a;
    }

    private static int min(int x, int y) {
        return x < y ? x : y;
    }

    private static int max(int x, int y) {
        return x < y ? y : x;
    }

    private static void printIntArray(int[] array, String delimeter) {
        System.out.println(Arrays.stream(array)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining(delimeter)));
    }
}



Measured memory_bytes: 33760
W=input()
s=0
try:
    while True:
        T=list(input().split())
        l=len(T)
        for i in range(l):
            if T[i]=="END_OF_TEXT":
                break
            else:
                t=T[i].lower()
                if t==W:
                    s+=1
                
except EOFError:
    pass
print(s)


Measured memory_bytes: 5560
n = gets.chomp.to_i

n.times do 
  l = gets.chomp.split
  3.times do |i|
    l[i] = l[i].to_i
  end
  l.sort!
  if l[0]**2 + l[1]**2 == l[2]**2
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 6108
import java.util.*;

public class Main {
    class P {
        int i;
        long w;

        public P(int i, long w) {
            this.i = i;
            this.w = w;
        }
    }
    boolean[] visited;
    boolean[] blacks;
    List<P>[] listArr;

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        listArr = new ArrayList[n + 1];

        visited = new boolean[n + 1];
        blacks = new boolean[n + 1];

        for (int i = 0; i < n + 1; i++) {
            listArr[i] = new ArrayList<P>();
        }

        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt();
            int v = sc.nextInt();
            long w = sc.nextLong();

            listArr[u].add(new P(v, w));
            listArr[v].add(new P(u, w));
        }

        dfs(1, true);

        for (int i = 1; i < n + 1; i++) {
            System.out.println(blacks[i] ?  "1" : "0");
        }
    }

    void dfs(int i, boolean isBlack) {
        if (visited[i]) return;
        visited[i] = true;
        if (isBlack) blacks[i] = true;
        List<P> pList = listArr[i];
        for (P p : pList) {
            boolean hoge = (blacks[i] && p.w % 2 == 0) || (!blacks[i] && p.w % 2 != 0);
            dfs(p.i, hoge);
        }
    }

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

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


Measured memory_bytes: 114484
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int n,a[N<<1];
bool check(int x){
	for(int i=1;i<n;i++){
		if(a[n+i]>=x&&a[n+i-1]>=x)return 1;
		if(a[n-i]>=x&&a[n-i+1]>=x)return 1;
		if(a[n+i]<x&&a[n+i-1]<x)return 0;
		if(a[n-i]<x&&a[n-i+1]<x)return 0;
	}
	return (a[n]<x)^(n&1);
}
int main(){
	n=read();
	for(int i=1;i<2*n;i++)a[i]=read();
	int l=1,r=n*2-1;
	while(l<r){
		int mid=(l+r)>>1; mid++;
		//cout<<check(mid)<<" "<<l<<" "<<r<<endl;
		if(check(mid))l=mid; else r=mid-1;
	}
	writeln(l);
}
/*
1
101
10101
*/

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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;
typedef long long ll;

struct UnionFind{
    vector<int> p;
    vector<int> r;

    UnionFind(int n){
        p.resize(n, -1);
        r.resize(n, 1);
    }

    int find(int x){
        if(p[x] == -1) return x;
        else return p[x] = find(p[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);

        if(x == y) return;
        if(r[x] > r[y]) swap(x, y);
        if(r[x] == r[y]) ++r[y];

        p[x] = y;
    }

    int same(int x, int y){
        x = find(x);
        y = find(y);

        return (x == y);
    }
};

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

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

    UnionFind uf(n);
    rep(_, q){
        int com, x, y;
        cin >> com >> x >> y;

        if(com == 0){
            uf.unite(x, y);
        }

        else{
            cout << uf.same(x, y) << endl;
        }
    }

    return 0;
}


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

int main(){
	int n,F[50];
	cin>>n;
	F[0] = F[1] = 1;
	for(int i=2;i<=n;i++) F[i] = F[i-1] + F[i-2];
	cout<<F[n]<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<math.h>
#include<string.h>
#define ll long long

using namespace std;
const int inf=0x3f3f3f3f;

int main()
{
    int n,p;
    cin>>n>>p;
    int s=n*3+p;
    cout<<s/2<<endl;
}


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

int main() {
  long n, k;
  cin >> n >> k;
  map<long, long> enemies;
  for (long i = 0; i < n; i++) {
    long tmp;
    cin >> tmp;
    if (enemies.count(tmp) > 0) {
      enemies[tmp] += 1;
    } else {
      enemies[tmp] = 1;
    }
  }
  
  long result = 0;
  for (auto i = enemies.rbegin(); i != enemies.rend(); i++) {
    long value = i->second;
    long tairyoku = i->first;
    if (k - value >= 0) {
      k = k - value;
    } else if (k > 0) {
      k = 0;
      result += (value - k) * tairyoku;
    } else {
      result += value * tairyoku;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 12800
a, b, c, d = map(int, input().split())

if d <= a or b <= c:
  print(0)
elif c <= a and b <= d:
  print(b-a)
elif a <= c and b <= d:
  print(b-c)
elif c <= a and d <= b:
  print(d-a)
elif a <= c and d <= b:
  print(d-c)
else:
  print(0)


Measured memory_bytes: 9128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int brk=0;
int main(){
	char a1,b1,c1,d1;
	int ans,a,b,c,d;
	cin>>a1>>b1>>c1>>d1;
	a=a1-'0',b=b1-'0',c=c1-'0',d=d1-'0';
	for(char i='+';i<='-';i++)
	    for(char j='+';j<='-';j++)
	        for(char k='+';k<='-';k++){
	            ans=a;
	            if(i=='+') ans+=b;
	            else if(i=='-') ans-=b;
	            if(j=='+') ans+=c;
	            else if(j=='-') ans-=c;
	            if(k=='+') ans+=d;
	            else if(k=='-') ans-=d;
	            if(ans==7){
	                cout<<a<<i<<b<<j<<c<<k<<d<<"="<<ans<<"\n";
	                return 0;
	            }
	        }
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, H := sc.nextInt(), sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	maxA := 0
	for i := 0; i < N; i++ {
		A[i] = sc.nextInt()
		B[i] = sc.nextInt()
		if A[maxA] < A[i] {
			maxA = i
		}
	}
	count := 0
	sort.Ints(B)
	for i := N - 1; i >= 0 && H > 0; i-- {
		if A[maxA] <= B[i] {
			H -= B[i]
			count++
		} else {
			break
		}
	}
	if H > 0 {
		count += ceil(H, A[maxA])
	}

	fmt.Fprintln(wtr, count)
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> vec(N);
  rep(i,N) cin >> vec[i];

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());//vectorの重複要素を削除

  cout << vec.size() << endl;

}


Measured memory_bytes: 3644
n,L=map(int,input().split())
lst=[]
for i in range(1,n+1):
    lst.append(L+i-1)
s=sum(lst)
if lst[0]>0:
    print(s-lst[0])
elif lst[-1]<0:
    print(s-lst[-1])
else:
    print(s)

Measured memory_bytes: 38384
s = list(map(str, input()))
l = len(s)
li = []
for i in range(l):
    if s[i] == "0":
        li.append(0)
    elif s[i] == "1":
        li.append(1)
    elif s[i] == "B" and li != []:
        li_len = len(li)
        li.pop(li_len-1)
ans = "".join(map(str, li))
print(ans)


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

char s1[610][610],s2[610][610];
unsigned long long sum1[610][610],sum2[610][610];
unsigned long long f[610*610];

unsigned long long getsum(unsigned long long sum[][610],int x,int y)
{
    if(x<0||y<0)return 0;
    return sum[x][y];
}

void csum(char str[][610],int n,unsigned long long sum[][610])
{
    unsigned long long pw=1;
    for(int i=0;i<2*n;i++)
        for(int j=0;j<2*n;j++)
        {
            sum[i][j]=(str[i][j]-'a'+1)*pw+getsum(sum,i-1,j)+getsum(sum,i,j-1)-getsum(sum,i-1,j-1);
            pw=pw*10007;
        }
}


int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s",s1+i);
        for(int j=0;j<n;j++)
        {
            s1[i][j+n]=s1[i][j];
            s1[i+n][j]=s1[i][j];
            s1[i+n][j+n]=s1[i][j];
        }
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            s2[i][j]=s1[j][i];
            s2[i+n][j]=s2[i][j];
            s2[i][j+n]=s2[i][j];
            s2[i+n][j+n]=s2[i][j];
        }
    csum(s1,n,sum1);
    csum(s2,n,sum2);

    int ans=0;
    unsigned long long t1,t2;
    f[0]=1;
    for(int i=1;i<610*610;i++)
        f[i]=f[i-1]*10007;
    long long delta;
    for(int i=n;i<2*n;i++)
        for(int j=n;j<2*n;j++)
        {
            t1=getsum(sum1,i,j)-getsum(sum1,i-n,j)-getsum(sum1,i,j-n)+getsum(sum1,i-n,j-n);
            t2=getsum(sum2,j,i)-getsum(sum2,j-n,i)-getsum(sum2,j,i-n)+getsum(sum2,j-n,i-n);
            delta=2*n*i+j-2*n*j-i;
            if(delta>0)
                t2=t2*f[delta];
            else
                t1=t1*f[-delta];
            if(t1==t2)
            {
                ans++;
            }
        }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9600
mod=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1
x=1
p=1
for i in range(a):
    p=p*(n-i)
    p%=mod
    x=x*(i+1)
    x%=mod
tmp1=(p*pow(x,mod-2,mod))%mod
y=1
q=1
for j in range(b):
    q=q*(n-j)
    q%=mod
    y=y*(j+1)
    y%=mod
tmp2=(q*pow(y,mod-2,mod))%mod
print((ans-tmp1-tmp2)%mod)

Measured memory_bytes: 39664
=begin
－－－－－－－－－－－－－－
N = 数列の長さ
h = 花の高さの最終目標
ans = 操作回数
－－－－－－－－－－－－－－
1: 数列の先頭の値を取り出し 残った数列 - 先頭の値 を 配列が空になるまで繰り返す
  1.1: 先頭の値が 正の数 の場合は ans に加算し、操作を続ける (負の数の場合 ans への加算は行わない: 操作しすぎた数を戻している作業になる)
2: ans を出力する 
=end

N = gets.to_i;
h = gets.split.map(&:to_i);
ans = 0;

while h.empty? == false do
  a = h.shift;
  ans += a if a > 0;
  h.map!{|v| v - a};
end

p ans


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int n;
  int q;
  cin >> n;
  if(n % 2 == 0)
  {
      cout << 0.5;
  }
  else
  {
    q = n /2 ;
    cout << (q + 1.0) / n;
  }
  return 0;
}

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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int x[N], y[N], h[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    int acx, acy, ah;
    for(int cx=0; cx <=100; cx++){
        for(int cy=0; cy<=100; cy++){
            // 0を無視して高さを仮決めする
            int H = -1;
            for(int i=0; i<N; i++){
                if(h[i] == 0) continue;
                int tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
                if(H == -1) H = tmp;
                if(H != tmp){
                    H = -2;
                    break;
                }
            }
            if(H == -2) continue;
            for(int i=0; i<N; i++){
                if(h[i] != 0) continue;
                int tmp = H - abs(x[i]-cx) - abs(y[i]-cy);
                if(tmp > 0){
                    H = -2;
                    continue;
                }
            }
            if(H != -2){
                acx = cx;
                acy = cy;
                ah = H;
            }
        }
    }

    cout << acx << " " << acy << " " << ah << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
int ncr(int n, int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

int fibonacci(int n){
    double phi = (1 + sqrt(5))/(double)2;
    int nth_fib = round(pow(phi,n)/sqrt(5));
    return nth_fib;
}
signed main(){

#ifndef ONLINE_JUDGE
   // freopen("input.txt","r", stdin);
#endif

    fastIO
    int n;
    cin >> n;
    int digit[10][10];
    memset(digit, 0, sizeof(digit));
    for(int i = 1; i <= n; i++){
        int ii, jj, temp = i;
        jj = i%10;
        while(temp > 0){
            ii = temp%10;
            temp /= 10;
        }
        digit[ii][jj] += 1;
    }
    int ans = 0;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            ans += digit[i][j] * digit[j][i];
        }
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def lagrange_interpolation(x,y,mod=mod):
        n = len(x)-1
        dp = [0]*(n+2)
        dp[0] = x[0]
        dp[1] = 1
        for i in range(n):
            nd = [0]*(n+2)
            ni = i+1
            for j in range(n+2):
                nj = j
                nd[nj] += -x[ni]*dp[j]
                nd[nj] %= mod
                if j <= n:
                    nj = j+1
                    nd[nj] += dp[j]
                    nd[nj] %= mod
            for j in range(n+2):
                dp[j] = nd[j]

        f = [0]*(n+1)
        for i in range(n+1):
            if y[i] == 0:
                continue
            fi = 1
            for j in range(n+1):
                if i == j:
                    continue
                fi *= x[i]-x[j]
                fi %= mod
            fi = pow(fi,mod-2,mod)
            p = [0]*(n+1)
            if x[i] == 0:
                for j in range(n+1):
                    p[j] = dp[j+1]
            else:
                inv = pow(x[i],mod-2,mod)
                p[0] = -dp[0]*inv%mod
                for j in range(1,n+1):
                    p[j] = (p[j-1]-dp[j])*inv%mod
            for j in range(n+1):
                f[j] += y[i]*fi*p[j]
                f[j] %= mod
        return f
    p = I()
    a = LI()
    f = lagrange_interpolation(list(range(p)),a,p)
    print(*f)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 46684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }

vector<vector<LL>> solve(LL n){
    for(LL k = 2; k <= n; ++k){
        LL r1 = n / k;
        LL r2 = n % k;
        if(r1 % 2 == 0 && r2 != 0) continue;
        if(r1 % 2 == 1 && r2 != k-1) continue;
        vector<vector<LL>> ans(k);
        for(LL i = 0; i < n; ++i){
            LL r3 = i / k;
            if(r3 % 2 == 0){
                ans[i%k].push_back(n-i);
            }else{
                ans[k-1-i%k].push_back(n-i);
            }
        }
        return ans;
    }
    return vector<vector<LL>>();
}

int main(){
    LL n;
    cin >> n;
    vector<vector<LL>> ans = solve(n);
    //cerr << ans << endl;
    vector<pair<LL,LL>> ans2;
    for(LL i = 0; i < ans.size(); ++i){
        for(LL j = i+1; j < ans.size(); ++j){
            for(LL u: ans[i]){
                for(LL v: ans[j]){
                    ans2.emplace_back(u, v);
                }
            }
        }
    }
    cout << ans2.size() << endl;
    map<LL,LL> cnt;
    for(auto p: ans2){
        cout << p.first << " " << p.second << endl;
        cnt[p.first] += p.second;
        cnt[p.second] += p.first;
    }
    /*
    cerr << cnt << endl;
    for(LL i = 2; i <= n; ++i){
        assert(cnt[1] == cnt[i]);
    }
    */
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main () {
  int n, k;
  cin >> n >> k;
  
  long long cnt = 0;
  long long min[n+1], max[n+1];
  min[0] = 0;
  max[0] = n;
  for (int i = 1; i < n + 1; ++i) {
    min[i] = min[i-1] % MOD + i;
    max[i] = max[i-1] % MOD + n - i;
  }
  
  for (int i = k - 1; i < n + 1; ++i) {
    if (max[i] - min[i] < 0) max[i] += MOD;
    cnt = cnt % MOD + (max[i] - min[i] +1);
  }
  cout << cnt % MOD;
}

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

int main()
{
	int k,s;
	cin>>k>>s;
	
	int i,j,y;
	int ans=0;
	for(i=0;i<=k;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(s-i-j<=k && s-i-j>=0)
			 ans++;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  printf("%s\n", (N==M)?"Yes":"No");
  return 0;
  
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int sum=0;
  for(int i=0; i<M; i++){
    cin >> A[i];
    sum += A[i];
  }
  if(sum>N){
    cout << "-1" << endl;
  }else{
    cout << (N-sum) << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
import sys
w=""
a=[]
while (w!="0 0"):
    w=input()
    a.append(w)
a.pop()
for st in a:
    b=st.split()
    h=int(b[0])
    w=int(b[1])
    for i in range(h):
        for j in range(w):
            if ((i+j)% 2==0):
                sys.stdout.write("#")
            else:
                sys.stdout.write(".")
        sys.stdout.write("\n")
    sys.stdout.write("\n")

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  sort(ALL(s));
  cout << (s == "abc" ? "Yes" : "No") << endl;
}

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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
        ll x1;
        cin >> x1;
        for(ll i = 0; i <= 1001 ; i ++)
        {
            for(ll j = 0; j < i ; j ++)
            {
                ll x = (ll)pow(i , (ll)5);
                ll y = (ll)pow(j , (ll)5);
                if( (x - y == x1))
                {
                    cout << i << " " << j << endl;
                    return 0;
                }
                if(x + y == x1)
                {
                    cout << i << " " << -1 * j << endl;
                    return 0;
                }
                
            }
        }  
   }
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust\n";
    else
        cout << "win\n";
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
	int N;cin>>N;

	int x;
	if(N&1)x=N;
	else x=N+1;
	vpint ans;
	for(int i=1;i<=N;i++)for(int j=i+1;j<=N;j++)if(i+j!=x)ans.pb({i,j});
	cout<<ans.size()<<endl;
	rep(i,ans.size())cout<<ans[i].fi<<" "<<ans[i].se<<endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
al = list(map(int,input().split()))

stack = [0,0,0]

ans = 1
for a in al:
    p = stack.count(a)
    ans *= p
    ans %= 1000000007
    for i in range(3):
        if stack[i] == a:
            stack[i] += 1
            break

print(ans)

Measured memory_bytes: 52952
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();       
		long c = sc.nextLong();
        long ans = 0;
        if(b>c){ans = (a*c)/b;}
        else{ans = (a*(b-1))/b;}
		System.out.println(ans);
	}
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
ll X[100000], A, B;

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

    std::cin >> N >> A >> B;

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

    ll cost = 0ll;
    for(int i=0;i+1<N;++i){
        ll d = X[i+1] - X[i];
        if(A * d < B){
            cost += A * d;
        }else{
            cost += B;
        }
    }

    std::cout << cost << std::endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		for(int i=0;i<N;i++)A[i]=sc.nextLong();
		sc.close();

		long ans = 0;
		for(int i=0;i<60;i++) {
			int cnt = 0;
			for(int j=0;j<N;j++) {
				if(((A[j]>>i)&1)==1) cnt++;
			}
			//long tmp = (long)cnt*(N-cnt)%mod;
			//long mul = ((long)1<<i)%mod;
			//long mul = (long)Math.pow(2, i) % mod;
			ans += (long)cnt * (((long)(N-cnt) * (((long)1<<i)%mod)%mod)%mod);
			//ans += (tmp * mul % mod);
			ans %= mod;	
		}
		System.out.println(ans);
	}
	
}

Measured memory_bytes: 99488
N, Y = map(int, input().split())

isHonest = False
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        yen = x * 10000 + y * 5000 + z * 1000
        if yen == Y:
            isHonest = True
            print(x, y, z)
            break
        elif yen > Y:
            break
    if isHonest == True:
        break

if isHonest == False:
    x, y, z = -1, -1, -1
    print(x, y, z)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int W, H;
int c[1234][1234];

int main(void)
{
	cin >> W >> H;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> c[i][j];
		}
	}
	for (int i = 1; i < H; ++i) {
		for (int j = 1; j < W; ++j) {
			if (c[i][j] ^ c[i][j - 1] ^ c[i - 1][j] ^ c[i - 1][j - 1]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	int ph[2] = {};
	int pw[2] = {};
	for (int i = 0; i < H; ++i) {
		ph[c[i][0]]++;
	}
	for (int j = 0; j < W; ++j) {
		pw[c[0][j]]++;
	}
	if (abs(ph[0] - ph[1]) > 1 || abs(pw[0] - pw[1]) > 1) {
		cout << "no" << endl;
		return 0;
	}
	cout << "yes" << endl;
	return 0;
}



Measured memory_bytes: 7912
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a[4], b[4];
    int sa, sb;

    sa = sb = 0;
    for (int i = 0; i < 4; i++)
        cin >> a[i];
    for (int i = 0; i < 4; i++)
        cin >> b[i];
    
    for (int i = 0; i < 4; i++) {
        sa += a[i];
        sb += b[i];
    }
    cout << max(sa, sb) << endl;

    return 0;
}

Measured memory_bytes: 1160
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    A,B = LMIIS()
    print(max(0,A-B*2))



if __name__ == '__main__':
    main()

Measured memory_bytes: 38460
n = gets.to_i
baggage = gets.split.map(&:to_i)
sorted = baggage.sort
sorted_index = sorted.map{ |s| baggage.index(s) }
cost = 0
used = [false] * n
n.times do |s|
  next if used[s]
  cur = s
  count = 0
  loop do
    count += 1
    used[cur] = true
    cost += baggage[cur]
    cur = sorted_index[cur]
    break if used[cur]
  end
  cost += [sorted[cur] * (count - 2), sorted[cur] + sorted[0] * (count + 1)].min
end
p cost

Measured memory_bytes: 8860
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, r;
    cin >> n >> r;
    if(n >= 10) cout << r << endl;
    else cout << r + 100 * (10 - n) << endl;
	return 0;
}

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

int main(){
    int n,cnt=0;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[minj]) minj = j;
        }
        if(minj!=i){
            swap(a[minj],a[i]);
            cnt++;
        }
    }
    for(int i=0;i<n-1;i++) cout << a[i] << " ";
    cout <<a[n-1] << endl;
    cout << cnt << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;


int main(){
    int N, P; cin >> N >> P;
    ll ans = 0;
    ll MAX = pow(2, N);
    vector<int> E, O;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a % 2 == 0) E.push_back(a);
        else if(a % 2 == 1) O.push_back(a);
    }
    int ON = O.size(); 
    int EN = E.size(); 
    vector<ll> NCk(ON + 2);
    NCk[0] = 1;
    NCk[1] = ON;

    for(int i = 2; i <= ceil((double)ON/2)+1; i++){
        NCk[i] = NCk[i-1] * (NCk[1]-i+1);
        NCk[i] = NCk[i]/i;
    }
    ll cons = pow(2, EN);
    ans += cons;
    for(int i = 2; i <= ON; i+=2){
        ans += cons*NCk[min(i, ON-i)];
    }
    if(P == 1) ans = MAX - ans;
    cout << ans << endl;
    

}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let nums = vec![
        read::<String>().chars().collect::<Vec<char>>(),
        read::<String>().chars().collect::<Vec<char>>(),
    ];

    let ans = nums
        .iter()
        .enumerate()
        .all(|(i, v)| v.iter().enumerate().all(|(j, &m)| nums[1 - i][2 - j] == m));

    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
ans = 0
# 赤パターンを列挙
for h_ptn in range(2 ** H):
  for w_ptn in range(2 ** W):
    cnt = 0
    # 1マスずつ黒マスの存在確認
    for h in range(H):
      for w in range(W):
        if (h_ptn >> h) & 1 == 0 and (w_ptn >> w) & 1 == 0:
          if C[h][w] == '#':
            cnt += 1
    if cnt == K:
      ans += 1
print(ans)

 

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

const int MAXSIZE = 25;
const int END = -1;
struct StNod
{
  int m_nDept;
  int m_nHigh;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nDept(END), m_nHigh(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  rvoNod.resize(MAXSIZE, oNod);

  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nParnt, nLeft, nRigt;
    cin >> nParnt >> nLeft >> nRigt;

    rvoNod[nParnt].m_nLeft = nLeft;
    rvoNod[nParnt].m_nRigt = nRigt;
    if (nLeft != END)  rvoNod[nLeft].m_nParnt = nParnt;
    if (nRigt != END)  rvoNod[nRigt].m_nParnt = nParnt;
  }
}

void fnSetDepth(vector<StNod> &rvoNod, int nx, int nDept)
{
  rvoNod[nx].m_nDept = nDept;
  
  if (rvoNod[nx].m_nLeft != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nLeft, nDept + 1);

  if (rvoNod[nx].m_nRigt != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nRigt, nDept + 1);
}

int fnSetHight(vector<StNod> &rvoNod, int nx)
{
  int nLHigh =0, nRHigh = 0;

  if (rvoNod[nx].m_nLeft != END)
    nLHigh = fnSetHight(rvoNod, rvoNod[nx].m_nLeft) + 1;
  if (rvoNod[nx].m_nRigt != END)
    nRHigh = fnSetHight(rvoNod, rvoNod[nx].m_nRigt) + 1;
  
  rvoNod[nx].m_nHigh = max(nLHigh, nRHigh);
  return rvoNod[nx].m_nHigh;
}

void fnBinTree(vector<StNod> &rvoNod)
{
  int nx = 0;
  while (rvoNod[nx].m_nParnt != END)
    nx = rvoNod[nx].m_nParnt;

  int nDept = 0;
  fnSetDepth(rvoNod, nx, nDept);

  int nHigh = fnSetHight(rvoNod, nx);
}

void fnResult(const vector<StNod> &cnrvoNod)
{
  for (int i = 0; i < cnrvoNod.size(); i++)
  {
    if (cnrvoNod[i].m_nDept == END)  break;
    cout << "node " << i << ": parent = " << cnrvoNod[i].m_nParnt << ", sibling = ";

    if (cnrvoNod[i].m_nParnt == END)  cout << END;
    else
    {
      int nx = cnrvoNod[i].m_nParnt;
      if (i == cnrvoNod[nx].m_nLeft)  cout << cnrvoNod[nx].m_nRigt;
      else                            cout << cnrvoNod[nx].m_nLeft;
    }
    
    cout << ", degree = ";
    int nCCnt = 0;
    if (cnrvoNod[i].m_nLeft != END)  nCCnt++;
    if (cnrvoNod[i].m_nRigt != END)  nCCnt++;
    cout << nCCnt << ", depth = " << cnrvoNod[i].m_nDept << ", height = " << cnrvoNod[i].m_nHigh;

    if (!cnrvoNod[i].m_nDept)       cout << ", root";
    else if (!cnrvoNod[i].m_nHigh)  cout << ", leaf";
    else                            cout << ", internal node";
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnBinTree(voNod);
  fnResult(voNod);
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

unsigned long long f(unsigned long long n) {
    if (n < 0) return 0;
    switch(n % 4) {
        case 0: return n;
        case 1: return 1;
        case 2: return n + 1;
        case 3: return 0;
    }
}

int main()
{
    unsigned long long a, b; cin >> a >> b;
    cout << (f(b) ^ f(a - 1)) << endl;
    return 0;
}

Measured memory_bytes: 256