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

vector<vector<int>> p(int n, int m, vector<vector<int>> &orgs) {
    vector<vector<int>> res;
    for(vector<int> org : orgs) {
        int start;
        if(n > 0) {
            start = org.at(n - 1);
        } else {
            start = 1;
        }
        int end = m;

        for(int i = start; i <= end; i++) {
            vector<int> ar(org.size());
            copy(org.begin(), org.end(), ar.begin());
            ar.at(n) = i;
            res.push_back(ar);
        }
    }
    return res;
}

vector<vector<int>> make_pattern(int m, int n) {
    vector<int> a(n);
    vector<vector<int>> res(1);
    res.at(0) = vector<int>(n);
    for(int i = 0; i < n; i++) {
        res = p(i, m, res);
    }
    return res;
}

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q);
    vector<int> b(Q);
    vector<int> c(Q);
    vector<int> d(Q);

    for(int i = 0; i < Q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--;
        b.at(i)--;
    }

    int ans = 0;
    vector<vector<int>> all = make_pattern(M, N);
    for(vector<int> A : all) {
        int score = 0;
        for(int i = 0; i < Q; i++) {
            if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) {
                score += d.at(i);
            }
        }
        ans = max(score, ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13232
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N, M;
int A[51], B[51];
vector<int> Mp[51];
int par[51]; //親
int tree_rank[51]; //木の深さ

void init_union_find(int n){
  rep(i, n){
    par[i] = i;
    tree_rank[i] = 0;
  }
}

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

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

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

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

  cin >> N >> M;
  int a, b;
  rep(i, M){
    cin >> a >> b;
    a--; b--;
    A[i] =a;
    B[i] =b;
  }
  int ans=0;
  rep(i, M){
    init_union_find(N);
    rep(j, M){
      if (j==i) continue;
      int a = A[j];
      int b = B[j];
      if(!same(a, b)){
        unite(a,b);
      }
    }
    if (!same(A[i], B[i])) ans++;
  }
  cout << ans << "\n";
  return 0;
}

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

#define pb push_back
using namespace std;
 
int main()
{
 

    int n,m;
    cin>>n>>m;
    long long sum=0;
    long x;
    for(int i=0;i<m;i++)
    {
    	cin>>x;
    	sum+=x;
    }

    if(sum<=n)
    	cout<<n-sum;
    else
    	cout<<-1;
 	
 	


	return 0;
}

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

typedef long long ll;
using namespace std;

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

    double bunbo = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        bunbo += (double) 1 / a;
    }

    double res = 1 / bunbo;
    printf("%.10f", res);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

size_t to_index(int x, int y, int w) {
	return y * w + x;
}

bool are_all_true(std::vector<bool>& v) {
	return std::all_of(v.begin(), v.end(), [](bool x) { return x; });
}

int main()
{
	int n, w, h;
	std::cin >> n >> w >> h;

	std::vector<bool> columns(w, false);
	std::vector<bool> rows(h, false);

	for (int i = 0; i < n; i++) {
		int x, y, kotod;
		std::cin >> x >> y >> kotod;

		std::fill(columns.begin() + std::max(0, x - kotod), columns.begin() + std::min(w, x + kotod), true);
		std::fill(rows.begin() + std::max(0, y - kotod), rows.begin() + std::min(h, y + kotod), true);
	}

	std::cout << (are_all_true(columns) || are_all_true(rows) ? "Yes\n" : "No\n");
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int H, W;
  cin >> H >> W;
  VVI xs(H, VI(W));
  cin >> xs;

  REP(y,H) REP(x,W) xs[y][x] %= 2;

  vector<pair<PII,PII>> ans;
  REP(y,H){
	REP(x,W-1){
	  if(xs[y][x]){
		ans.PB(MP(MP(y,x), MP(y,x+1)));
		(xs[y][x+1] += 1) %= 2;
	  }
	}
  }
  REP(y,H-1){
	if(xs[y][W-1]){
	  ans.PB(MP(MP(y,W-1), MP(y+1,W-1)));
	  (xs[y+1][W-1] += 1) %= 2;
	}
  }

  cout << SZ(ans) << endl;
  for(auto p: ans)
	cout << p.FF.FF+1 << " " << p.FF.SS+1 << " " << p.SS.FF+1 << " " << p.SS.SS+1 << endl;

  return 0;
}


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

const int maxn=2e5+7;
int n,q,a,b,dfn[maxn],in[maxn],out[maxn],del[maxn],sum,ans[maxn];
vector<int> to[maxn];

void dfs(int x,int f)
{
	dfn[++dfn[0]]=x;
	in[x]=dfn[0];
	for(int i=0;i<to[x].size();++i) {
		int t=to[x][i];
		if(t==f) continue;
		dfs(t,x);
	}
	out[x]=dfn[0];
}

int main()
{
	scanf("%d %d",&n,&q);
	for(int i=1;i<n;++i) {
		scanf("%d %d",&a,&b);
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(1,0);
	for(int i=1;i<=q;++i) {
		scanf("%d %d",&a,&b);
		del[in[a]]+=b;
		del[out[a]+1]-=b;
	}
	for(int i=1;i<=n;++i) {
		sum+=del[i];
		ans[dfn[i]]=sum;
	}
	for(int i=1;i<=n;++i) printf("%d ",ans[i]);
}

Measured memory_bytes: 29696
class UF_weighed:
    def __init__(self, n):
        self.n = n
        self.par = list(range(n+1))
        self.rank = [0]*(n+1)
        self.size = [1]*(n+1)
        self.diff_w = [0]*(n+1)

    def find(self, x):
        if self.par[x] == x: return x
        p = self.find(self.par[x])
        self.diff_w[x] += self.diff_w[self.par[x]]
        self.par[x] = p
        return self.par[x]

    def weight(self, x):
        self.find(x)
        return self.diff_w[x]

    def diff(self, x, y):
        if not self.same(x, y): return None
        return self.weight(y) - self.weight(x)

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def merge(self, x, y, w):
        w += self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            x, y, w = y, x, -w
        self.par[y] = x
        self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.diff_w[y] = w
        return True
      
def main():
  n,m = map(int, input().split())
  uf = UF_weighed(n+1)
  for _ in range(m):
    a, b, c = map(int, input().split())
    if uf.same(a, b) and uf.diff(a, b) != c:
      return 'No'
    uf.merge(a, b, c)
  return 'Yes'

print(main())


Measured memory_bytes: 11552
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (sc.hasNext()) {
			double w= sc.nextDouble();
			if(w<=48){
				System.out.println("light fly");
			}else if(w>48 && w<=51){
				System.out.println("fly");
			}else if(w>51 && w<=54){
				System.out.println("bantam");
			}else if(w>54 && w<=57){
				System.out.println("feather");
			}else if(w>57 && w<=60){
				System.out.println("light");
			}else if(w>60 && w<=64){
				System.out.println("light welter");
			}else if(w>64 && w<=69){
				System.out.println("welter");
			}else if(w>69 && w<=75){
				System.out.println("light middle");
			}else if(w>75 && w<=81){
				System.out.println("middle");
			}else if(w>81 && w<=91){
				System.out.println("light heavy");
			}else if(w>91){
				System.out.println("heavy");
			}
		}

	}

}

Measured memory_bytes: 27776
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, A, R;
      cin >> N >> A;
      R = N % 500;
      if (R <= A){
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }

Measured memory_bytes: 256
# 階乗 x!
def fact(x):
    if x<1:
        return 1
    global p
    res=1
    for i in range(2, x+1):
        res=(res*i)%p
    return res

p=10**9+7
N,M=map(int,input().split())

if abs(N-M)>1:
    ans=0
else:
    ans=(fact(N)*fact(M))%p
if N==M:
    ans=(ans*2)%p

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int dp[200005];
int a[200005];
int main()
{
    int n;
    cin>>n;

    for(int i=1; i<=n; i++) cin>>a[i];
    dp[2]=abs(a[2]-a[1]);
    for(int i=3; i<=n; i++)
    {
        int x=dp[i-1]+abs(a[i]-a[i-1]);
        int y=dp[i-2]+abs(a[i]-a[i-2]);
        //cout<<x<<" "<<y<<endl;
        dp[i]=min(x,y);
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b/2 - a[c]) < abs(b/2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Measured memory_bytes: 15572
// Problem C

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <iomanip>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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

double A, B, H, M;

int main() {
  cin >> A >> B >> H >> M;
  double alpha = M_PI / 6.0 * (H + M/60.0);
  double xa = A*cos(alpha);
  double ya = A*sin(alpha);
  
  double beta = M_PI / 30.0 * M;
  double xb = B*cos(beta);
  double yb = B*sin(beta);
  
  cout << setprecision(50) << sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb)) << endl;
  
  return 0;
}


Measured memory_bytes: 4164
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


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


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

#define max(a,b) (((a) < (b)) ? (b) : (a))
#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int N;
    int a;
    int free = 0;
    int minkind = 0;
    int maxkind = 0;
    vector<int> rate(8,0);
    cin >> N;

    
    for(int i=0;i<N;i++) {
        cin >> a;
        a /= 400;
        if(a >= 8) {
            free++;
        } else {
            rate[a]++;
        }
    }

    for(int i=0;i<8;i++) {
        if(rate[i] > 0) {
            minkind++;
        }
    }

    maxkind =minkind + free;
    if(free > 0){
        minkind = max(1,minkind);
    }
//    maxkind = min(8,minkind + free);
    cout << minkind << " " << maxkind << "\n";
    return 0;
}

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

const int N = 2e5+100;
int p[N], ok[N];

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k;cin >> n >> k;
	for(int i=0 ; i<n ; i++)
		cin >> p[i];
	ok[n-1] = 1;
	for(int i=n-2 ; i>=0 ; i--)
		ok[i] = (p[i] < p[i+1] ? ok[i+1] : 0) + 1;
	bool nc = (ok[0] >= k);
	set<int> st;
	int ans=(ok[0] < k);
	for(int i=0 ; i<k-1 ; i++)
		st.insert(p[i]);
	for(int i=1 ; i<=n-k ; i++){
		st.erase(p[i-1]);
		st.insert(p[i+k-2]);
		if(ok[i] >= k){
			nc = true;
			continue;
		}
		if(p[i-1] > *st.begin() || p[i+k-1] < *st.rbegin())
			ans ++;
	}
	cout << ans+nc << "\n";
	return 0;
}
















Measured memory_bytes: 11264
from itertools import combinations, product
from collections import defaultdict

N = int(input())

edges = set()
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in set(range(1, N + 1)) - set([i, N + 1 - i]):
            edges.add((i, j) if i <= j else (j, i))
else:
    for i in range(1, N):
        for j in set(range(1, N)) - set([i, N - i]):
            edges.add((i, j) if i <= j else (j, i))
        edges.add((i, N))
    for i in range(1, N):
        edges.add((i, N))

print(len(edges))
for i, j in edges:
    print(i, j)

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int K, T; cin >> K >> T;
    int a[T]; rep(i, T) cin >> a[i];
    sort(a, a + T, greater<int>());
    int sum = 0;
    rep(i, T - 1)
        sum += a[i + 1];
    cout << ((a[0] - sum - 1 < 0) ? 0 : a[0] - sum - 1) << endl;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

void dfs(const vvi& g,int u,vi& vis,vi& order)
{
	if(vis[u]) return;
	vis[u]=1;
	for(int v:g[u]) if(!vis[v])
		dfs(g,v,vis,order);
	order.push_back(u);
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vvi g(n);
		for(int i=0;i<m;i++){
			int u,v; cin>>u>>v; u--,v--;
			g[u].push_back(v);
		}
		vi vis(n),order;
		for(int i=0;i<n;i++) if(!vis[i])
			dfs(g,i,vis,order);
		
		for(int i=order.size();i--;)
			cout<<order[i]+1<<endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    
    int bits_size = S.size() - 1;
    
    int64_t total = 0;
    for (int i = 0; i < (1 << bits_size);  i++) {
        bitset<10> plus_place(i);
        
        int64_t subtotal = 0;
        
        int start = 0, end = 0;
        for (int j = 0; j < bits_size; j++) {
            if(plus_place.test(j)) {
                end = j;
                subtotal += stoll(S.substr(start, end - start + 1));
                start = end + 1;
            }
        }
        subtotal += stoll(S.substr(start));
        total += subtotal;
    }
    cout << total << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define SIZE 100005

using namespace std;
typedef long long int ll;

ll A[SIZE],B[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	for(int i=0;i<n;i++) scanf("%lld",&B[i]);
	ll sa=0,sb=0;
	for(int i=0;i<n;i++) sa+=A[i],sb+=B[i];
	if(sa<sb)
	{
		puts("-1");
		return 0;
	}
	int cnt=0;
	ll d=0;
	vector <ll> vx;
	for(int i=0;i<n;i++)
	{
		if(A[i]<B[i])
		{
			d+=B[i]-A[i];
			cnt++;
		}
		else
		{
			vx.push_back(A[i]-B[i]);
		}
	}
	sort(vx.begin(),vx.end(),greater <ll>());
	for(int i=0;i<vx.size();i++)
	{
		if(d>0)
		{
			d-=vx[i];
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2808
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	jobs := make(Jobs, n)
	ih := &IntHeap{}
	heap.Init(ih)

	for i := 0; i < n; i++ {
		jobs[i].a = m - getNextInt(scanner)
		jobs[i].b = getNextInt(scanner)
	}
	sort.Sort(jobs)
	ii := 0
	for i := 0; i <= m; i++ {
		for ii < n && jobs[ii].a <= i {
			if jobs[ii].a >= 0 {
				heap.Push(ih, jobs[ii].b)
			}
			ii++
		}
		for ih.Len() > i+1 {
			heap.Pop(ih)
		}
	}

	ans := 0
	for ih.Len() > 0 {
		p := heap.Pop(ih).(int)
		ans += p
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Job struct {
	a, b, c int
}

type Jobs []Job

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

	return a[i].a < a[j].a
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 8320
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int k = Integer.parseInt(s[1]);
    int[] arr = new int[n];
    //int sum = 0;
    String[] str = br.readLine().split(" ");
    for(int i=0;i<n;i++){
      arr[i] = Integer.parseInt(str[i]);
      //sum += arr[i];
     // System.out.print(arr[i]+" ");
    }
    boolean[] dp = new boolean[k+1];
    Arrays.fill(dp,false);
    for(int i=0;i<=k;i++){
      for(int j=0;j<n;j++){
        if(i-arr[j]<0)
          break;
        else if(dp[i-arr[j]]==false){  
          dp[i] = true;
          break;
        }
      }
      //System.out.print(dp[i]+" ");
    }
         if(dp[k]==true)
    System.out.println("First");
  else
    System.out.println("Second");
    
    
 
  }
}

Measured memory_bytes: 33676
#include<iostream>
#include<algorithm>
#include<cstdio>
#define int long long
using namespace std;
void wk();
main(){int test=1;//scanf("%d",&test);
while(test--)wk();}
void wk(){
	string s;cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes";else cout<< "No";cout<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int h,w;
    cin >> h >> w;
    long a[h][w];
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    long hoge;
    rep(i,h){
        rep(j,w){
            cin >> hoge;
            a[i][j] = abs(a[i][j]-hoge);
        }
    }
    vector<bool> dp[h][w];
    rep(i,h){
        rep(j,w){
            rep(k,16000) dp[i][j].push_back(false);
        }
    }
    dp[0][0][a[0][0]] = true;
    //cout << "meu" << endl;
    rep(i,h){
        rep(j,w){
            rep(k,16000){
                if(dp[i][j][k]){
                    if(j!=w-1){
                        dp[i][j+1][k+a[i][j+1]]=true;
                        dp[i][j+1][abs(k-a[i][j+1])]=true;
                    }
                    if(i!=h-1){
                        dp[i+1][j][k+a[i+1][j]]=true;
                        dp[i+1][j][abs(k-a[i+1][j])]=true;                        
                    }
                } 
            }
        }
    }
    rep(i,16000){
        if(dp[h-1][w-1][i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 15512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{/*ノード作成*/
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer p;
  int i;
  p=nil->next;

  while((p != nil) && (p->key!=key)){
    p=p->next;
  }
    return p;

}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /*node の消去*/
  t->prev->next=t->next;
  t->next->prev=t->prev;
}

void deleteFirst(){
  /*最初のノードの削除*/
  NodePointer t = nil->next;
  if ( t == nil )return;
  deleteNode(t);
}

void deleteLast(){
  /*最後のノード削除*/
  NodePointer t=nil->prev;
  if(t==nil)return;
  deleteNode(t);

}

void delete(int key){

  NodePointer tea;
  if((tea=listSearch(key))!= NULL){
    if(tea == nil) return;
    deleteNode(tea);
    }
}


void insert(int key){
  /*挿入*/
  NodePointer new;
  new = malloc(sizeof(struct node));
  new->key = key;
  new->next=nil->next;
  
  nil->next->prev=new;

  nil->next=new;

  new->prev=nil;
}



int main(void){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) {
deleteFirst();
}
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

Measured memory_bytes: 34976
import java.util.Scanner;

public class Main {

    private Scanner in = new Scanner(System.in);

    void solve() {
        long n = in.nextLong(), m = in.nextLong();
        if(n == 2 || m == 2) {
            System.out.println(0);
            return;
        }
        long ans = Math.max(1, n - 2) * Math.max(1, m - 2);
        System.out.println(ans);
    }
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
#define PI 4*atan(1)
#define INF 1e8
 
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
 
int main(){
  int N;
  cin >> N;
  vector<unsigned long long> T(N), A(N), ans(N, 1);
  for(int i = 0; i < N; i++)cin >> T[i];
  for(int i = 0; i < N; i++)cin >> A[i];
  unsigned long long max_T = 0;
  for(int i = 0; i < N; i++){
    if(max_T < T[i]) max_T = T[i];
    else {
      ans[i] = T[i];
    }
  }
  unsigned long long max_A = 0;
  for(int i = N - 1; i >= 0; i--){
    if(max_A < A[i]){
      max_A = A[i];
      if (ans[i] == 1 && T[i] != A[i]) ans[i] = 0;
      else if (ans[i] != 1 && T[i] < A[i]) ans[i] = 0;
      else ans[i] = 1;
    } else {
      if (ans[i] == 1 && T[i] > A[i]) ans[i] = 0;
      ans[i] = min(ans[i], A[i]);
    }
  }
  unsigned long long ans_m = 1;
  for(int i = 0; i < N; i++){
    ans_m *= ans[i];
    ans_m %= 1000000007;
  }
  cout << ans_m << endl;
}


Measured memory_bytes: 2560
import sys, os
import collections
import math

def solve(input_stream):
  line = input_stream.readline().strip()
  length = len(line)
  border_before = math.floor(length/2)
  border_after = math.ceil(length/2)
  
  before = line[0:border_before]
  after = line[border_after:length][::-1]

  ans = 0
  for a, b in zip(before, after):
    if a != b:
      ans += 1
  
  return [str(ans)]

  
  

if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define endl '\n'
#define ll 'long long'

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

	int x, n;
	cin >> x >> n;
	int k = n;
	if (n == 0) cout << x;
	else {
		vector<int> vec;
		while (n != 0) {
			int p;
			cin >> p;
			vec.push_back(p);
			n--;
		}
		int target1 = 0;
		int target2 = 0;
		for (int i = 0; i < k; i++) {
			vector<int>::iterator result = find(vec.begin(), vec.end(), x + i);
			if (result == vec.end()) {
				target1 = (x + i);
				break;
			}
		}
		for (int j = 0; j < k; j++) {
			vector<int>::iterator result = find(vec.begin(), vec.end(), x - j);
			if (result == vec.end()) {
				target2 = (x - j);
				break;
			}
		}
		if ((x - target2) <= (target1 - x)) cout << target2;
		else cout << target1;
	}
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);

}

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

class Solve {
public:
    Int nibeki(Int n) {
        Int ret = 0;
        while (n % 2 == 0) {
            ret++;
            n >>= 1;
        }
        return ret;
    }

    void solve() {
        Int N, M;
        cin >> N >> M;
        vector<Int> A(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        for (int i = 0; i + 1 < N; ++i) {
            if (nibeki(A[i]) != nibeki(A[i + 1])) {
                cout << 0 << endl;
                return;
            }
        }

        Int hL = A[0] / 2; // half l
        for (int i = 0; i < N; ++i) {
            hL = lcm(hL, A[i] / 2);
            if (hL > M) {
                cout << 0 << endl;
                return;
            }
        }
        Int ans = 1 + (M - hL) / (2 * hL);
        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1024
l = map (int, raw_input().split())

if l[0] > l[1]:
    s = l[0]
    l[0] = l[1]
    l[1] = s
if l[2] > l[0]:
    if l[2] < l[1]:
        s = l[1]
        l[1] = l[2]
        l[2] = s
else:
    s = l[2]
    l[2] = l[1]
    l[1] = l[0]
    l[0] = s
print l[0], l[1], l[2]

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

vector<int> g[100005];
int dp[100005];

void dfs(int cur){
    if(dp[cur] != 0) return;
    for(int i = 0; i < g[cur].size(); i++){
        dfs(g[cur][i]);
        dp[cur] = max(dp[cur], dp[g[cur][i]] + 1);
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        dfs(i);
        ans = max(ans, dp[i]);
    }
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>

using namespace std;



long solve() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long n;
    char c;
    long facing_east = 0;
    long diff = 0;
    long min_diff = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> c;
        if (c == 'E') {
            ++facing_east;
            --diff;
            min_diff = min(min_diff, diff);
        } else {
            ++diff;
        }
    }
    
    return facing_east + min_diff;
}

int main() {
    cout << solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll a, b, c, k; cin >> a >> b >> c >> k;

    if (k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int sellectionsort(vector<int> &a)
{
    int minj,t,count=0;
    unsigned int i,j;
    for(i=0;i<a.size();i++)
    {
        minj = i;
        for(j=i;j<a.size();j++)
        {
            if(a[j]<a[minj])
            {
                minj = j;
            }
        }
        if(minj!=i)
        {   t = a[i];
            a[i] = a[minj];
            a[minj] = t;
            count++;
        }
    }
    return count;
}
int main()
{
    int n,m;
    vector<int> a;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        a.push_back(m);
    }
    m = sellectionsort(a);
    for(int i=0;i<n;i++)
    {
        if(i)
            cout<<' ';
        cout<<a[i];
    }
    cout<<endl;
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, a;
	cin >> n;

	int n_4 = 0;
	int n_2 = 0;
	int n_1 = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;

		if (a % 4 == 0) {
			n_4++;
		} else if (a % 2 == 0) {
			n_2++;
		} else {
			n_1++;
		}
	}

	bool ok = n_4 >= n_1;
	if (n_4 + 1 == n_1 && n_2 == 0) {
		ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  int cnt,tmp;
  int sum=0;
  
  scanf("%d", &N);

  for(tmp=1,cnt=0;tmp<=N;tmp*=10,cnt++)
    if(cnt%2==1)
      sum += tmp/10*9;

  if(cnt%2==1)
    sum += (N-tmp/10)+1; 

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


Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
   int n;
   cin>>n;
   int dp[n];
   int arr[n];
   for(int i=0;i<n;i++)
   cin>>arr[i];
   dp[n-1]=1;
   int maxi=1;
   for(int i=n-2;i>=0;i--)
   {
       if(arr[i]>=arr[i+1])
       dp[i]=1+dp[i+1];
       else dp[i]=1;
       maxi=max(maxi,dp[i]);
   }
   cout<<maxi-1<<endl;
   
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
int arr[1001][1001];
int main(){
string a[1005];
const int MOD=1e9+7;
int h,w;
cin>>h>>w;
string s;
fo(i,h){
    cin>>s;
    a[i]=s;
}
fo(i,h){
    fo(j,w){
        arr[i][j]=0;
    }
}


FOR(i,0,h-1){
    FOR(j,0,w-1){
    if(a[i][j]=='.'){
        if(i==0&&j==0) {arr[i][j]=1;}

        else if(i==0) arr[i][j]=arr[i][j-1];

        else if(j==0) arr[i][j]=arr[i-1][j];

        else arr[i][j]=(arr[i-1][j]+arr[i][j-1])%MOD;

    }
    }
}
cout<<arr[h-1][w-1]<<endl;






}

Measured memory_bytes: 5248
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double d = sc.nextDouble();
        double[] x = new double[n];
        double[] y = new double[n];
        int ans = 0;
        for (int i = 0; i < x.length; i++) {
            x[i] = sc.nextDouble();
            y[i] = sc.nextDouble();
            double xx = x[i] * x[i];
            double yy = y[i] * y[i];
            double tmp = Math.sqrt(xx + yy) ;
            if(d >= tmp) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

#define INF 10000000
using namespace std;

int main(void){
  int n;
  int ans = INF;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  
  for(int i = 0;i < n;i++){
    int temp = a[i];
    int count = 0;
    while(temp % 2 == 0){
      temp /= 2;
      count++;
    }
    
    ans = min(ans, count);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;



int32_t main()
{
    fast

   int test=1;
    //cin>>test;
  
   

  while(test--)
  {
    
   int d,t,s;
   cin>>d>>t>>s;

   if(d<=t*s)cout<<"Yes";
   else cout<<"No";

// while ending
   }
  

return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <set>

void addCards(std::set<int>& ranks) {
	for (int i = 1; i <= 13; i++) {
		ranks.insert(i);
	}
}

void printCards(char suit, std::set<int> ranks) {
	std::set<int>::iterator it = ranks.begin();
	while (it != ranks.end()) {
		std::cout << suit << " " << (*it) << "\n";
		it++;
	}
}

int main()
{
	std::set<int> spades, hearts, clubs, diamonds;
	addCards(spades);
	addCards(hearts);
	addCards(clubs);
	addCards(diamonds);

	int deckSize;
	std::cin >> deckSize;
	char suit;
	int rank;

	for (int i = 0; i < deckSize; i++) {
		std::cin >> suit >> rank;
		switch (suit)
		{
			case 'S':
				spades.erase(rank);
				break;
			case 'H':
				hearts.erase(rank);
				break;
			case 'C':
				clubs.erase(rank);
				break;
			case 'D':
				diamonds.erase(rank);
				break;
		}
	}

	printCards('S', spades);
	printCards('H', hearts);
	printCards('C', clubs);
	printCards('D', diamonds);

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
void solve() {
        int a, b;
        cin >> a >> b;
        cout << max(a+b, max(a-b, a*b)) << '\n';
        return ;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}


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

template <typename monoid>
class segmentTree {
public:
    using M = monoid;
    using T = typename M::value_type;

    int sz;
    vector<T> x;

    segmentTree(int n = 0) {
        sz = 1;
        while(sz < n) sz *= 2;
        x.assign(sz*2, M::id());
        init();
    }

    void fill(const T& val) {
        fill(x.begin() + sz, x.end(), val);
        init();
    }

    void init() {
        for(int i=sz-1; i>=1; --i) {
            x[i] = M::op(x[i*2], x[i*2+1]);
        }
    }

    T query(int l, int r) const {
        T al = M::id(), ar = M::id();
        for(l += sz, r += sz; l<r; l/=2, r/=2) {
            if(l&1) al = M::op(al, x[l++]);
            if(r&1) ar = M::op(x[--r], ar);
        }
        return M::op(al, ar);
    }

    void update(int i, const T &val) {
        x[i += sz] = val;
        while(i > 1) {
            x[i/2] = M::op(x[i], x[i^1]);
            i /= 2;
        }
    }

    T operator[](int i) const { return x[sz+i]; }
};

template <typename T>
struct min_monoid {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::max(); }
    static T op(const T &a, const T &b) { return min(a, b); }
};

template <typename T>
struct max_monoid {
    using value_type = T;
    static constexpr T id() { return std::numeric_limits<T>::min; }
    static T op(const T &a, const T &b) { return max(a, b); }
};

template <typename T>
struct sum_monoid {
    using value_type = T;
    static constexpr T id() {return 0;}
    static T op(const T &a, const T &b) { return a+b; }
};

template <typename T>
using rmq = segmentTree<min_monoid<T>>;

template <typename T>
using rsq = segmentTree<sum_monoid<T>>;

signed main() {
    int n, q;
    cin >> n >> q;
    rmq<int> seg(n);
    for(int i=0; i<q; ++i) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0) {
            seg.update(x, y);
        } else {
            y++;
            cout << seg.query(x, y) << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3888
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n=26, i = 0, j;
	int flag = 0;
	int ans = 0;
	char s[30] = {};
	cin >> s;
	//cout << s[0] << s[2] << s[6] << s[8] << s[9];
	
	for (i = 0; i < n; i++) {
		if (s[i] != s[29]) {
			for (j = i + 1; j < n; j++) {
				if (s[i] == s[j]) {
					flag = 1;
				}
			}
		}
		else ;
	}
	
	if (flag == 1) cout << "no" << "\n";
	else cout << "yes" << "\n";

}

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

# checking to see if N can create S
k = 0 # len of s
for i in range(1,N+1):
  if N==(i*(i+1))//2:
    k = i
    break
if not k:
  print("No")
  exit()

S = [ [0]*k for _ in range(k+1) ]

base,span = 1,k
for i in range(k):
  S[i][i:i+span+1] = list(range(base, base+span))

  for j in range(span):
    S[i+j+1][j] = base+j

  base,span = base+span,span-1

# for s in S:
#   print(s)

print("Yes")
print(k+1)
for s in S:
  print(" ".join([ str(s) for s in [k]+s ]))

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    //値と割る値を受け取って、オブジェクトを返す
    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        //負の値を受け取ったときには正の値に戻す
        if(n < 0){
            n += p;
        }
    }

    inline ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    inline ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    inline ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    inline int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    inline int modinv(int b){
        return modpow(b, p - 2);
    }

    inline ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};

int main(){

    int k;
    cin >> k;
    string s;
    cin >> s;

    int size = s.size();

    vector<ModInt> fact(k + size + 1);
    fact[0] = ModInt(1, MODN);

    for(int i = 1; i <= k + size; i++){
        fact[i] = fact[i - 1] * ModInt(i, MODN);
    }

    function<ModInt(int, int)> combi = [&](int n, int m) -> ModInt{
        return fact[n] / fact[n - m] / fact[m];
    };

    ModInt ans = ModInt(0, MODN);

    vector<ModInt> pow25(k + size + 1, ModInt(1, MODN));
    vector<ModInt> pow26(k + size + 1, ModInt(1, MODN));

    for(int i = 1; i <= k + size; i++){
        pow25[i] = pow25[i - 1] * ModInt(25, MODN);
    }

    for(int i = 1; i <= k + size; i++){
        pow26[i] = pow26[i - 1] * ModInt(26, MODN);
    }

    for(int i = size; i <= size + k; i++){

        int before = i - size;
        int after = size + k - i;

        ans = ans + combi(i - 1, size - 1) * pow25[before] * pow26[after];
    }

    cout << ans.n << endl;

    return 0;
}


Measured memory_bytes: 98176
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

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

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {

		out.println((nextInt() * 3 + nextInt()) / 2);
	}

	private void solveB() {
		int n = nextInt();
		String[][] s = new String[n][3];

		for (int i = 0; i < n; i++) {
			s[i][0] = next();
			s[i][1] = next();
			s[i][2] = Integer.toString(i + 1);
		}
		Arrays.sort(s,
				(x, y) -> {
					if (x[0].compareTo(y[0]) < 0) {
						return -1;
					} else if (x[0].compareTo(y[0]) > 0) {
						return 1;
					} else {
						return -Integer.compare(Integer.parseInt(x[1]), Integer.parseInt(y[1]));
					}
				});

		for (int i = 0; i < s.length; i++) {
			out.println(s[i][2]);
		}
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 26452
import heapq

city_num, road_num, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver  = min(MAX_COST, init_silver)

G = [[] for _ in range(city_num)]
for _ in range(road_num):
    A, B, cost, time_cost = map(int, input().split())
    A, B = A-1, B-1
    G[B].append([A, cost, time_cost])
    G[A].append([B, cost, time_cost])

for n in range(city_num):
    cost, time_cost = map(int, input().split())
    G[n].append([n, -cost, time_cost])

dp = [[float("inf")] * (MAX_COST+1) for _ in range(city_num)]
dp[0][init_silver] = 0
hq = [(0, 0, init_silver)]
while hq:
    time, node, silver = heapq.heappop(hq)
    for to, silver_cost, time_cost in G[node]:
        remain = min(silver - silver_cost, MAX_COST)
        if remain < 0:
            continue
        dp_next_value = time + time_cost
        if dp[to][remain] <= dp_next_value:
            continue
        dp[to][remain] = dp_next_value
        heapq.heappush(hq, (dp_next_value, to, remain))
print(*[min(d) for d in dp[1:]], sep="\n")

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

int main()
{
	int n; cin>>n;
	vector<vector<pair<int,int>>> vg(n);
	for(int i=0;i<n-1;i++){
		int u,v,w; cin>>u>>v>>w;
		u--; v--;
		vg[u].emplace_back(make_pair(v,w));
		vg[v].emplace_back(make_pair(u,w));
	}
	vector<int> g(n,-1);
	g[0]=0;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int idx=q.front(); q.pop();
		for(int i=0;i<vg[idx].size();i++){
			int next=vg[idx][i].first;
			int next_w=vg[idx][i].second;
			if(g[next]==-1){
				if(next_w%2==0) g[next]=g[idx];
				else{
					if(g[idx]==0) g[next]=1;
					else g[next]=0;
				}
				q.push(next);
			}
		}
	}
	//output
	for(int i=0;i<n;i++){
		cout<<g[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 6784