akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
 int n;

void solve(string s,char mx){
    if(s.length()==n){cout<<s<<endl;return ;}
    for(int i=0;i<n;i++){
       char c=i+'a';
        if(c<=mx)solve(s+c,mx);
        else if(c==mx+1)solve(s+c,mx+1);
    }
    return ;
}

int main(){
   cin>>n;
    solve("a",'a');
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll a[100005],b[100005];

// union-find-simple-ver

struct uftree{
	int par[200005];
	int rank[200005];
	ll dp[200005];
	ll bsum[200005];
	uftree(){
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}

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

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


uftree uf;
int n,m;

vector<int> G[100005];
bool flag[200005];
ll maxi=0;
vector<P> vi;

int main(void){
	scanf("%d%d",&n,&m);
	ll all=0;
	uf.init(n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		all+=b[i];
		vi.push_back(P(max(0LL,a[i]-b[i]),i));
		uf.bsum[i]=b[i];
	}
	
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	sort(vi.begin(),vi.end());
	for(int i=0;i<vi.size();i++){
		ll mini=vi[i].first;
		int v=vi[i].second;
		for(int j=0;j<G[v].size();j++){
			if(!flag[G[v][j]])continue;
			int nv=uf.find(G[v][j]);
			mini=min(mini,max(uf.dp[nv],(ll)vi[i].first-uf.bsum[nv]));
		}
		flag[v]=true;
		for(int j=0;j<G[v].size();j++){
			if(flag[G[v][j]]){
				uf.unite(v,G[v][j]);
			}
		}
		uf.dp[uf.find(v)]=mini;
	}
	printf("%lld\n",uf.dp[uf.find(0)]+all);
	return 0;
}

Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N, K;
  cin >> N >> K;
  lint sq = 0;
  while(true) {
    if((sq+1)*(sq+1) >= N) break;
    sq++;
  }
  lint size = sq*2;
  if((sq+1)*(sq+1) == N) size++;
  vector<lint> state(size, 1);
  lint tmp = N;
  REP(i, sq) {
    state[size-i-1] = tmp - max(sq, N/(i+2));
    tmp = N/(i+2);
  }
  vector<vector<lint>> dp(K, vector<lint>(size));
  REP(i, size) dp[0][i] = state[i];
  REP(i, size-1) dp[0][i+1] = (dp[0][i] + dp[0][i+1]) % MOD;
  FOR(i, 1, K) {
    REP(j, size) dp[i][j] = dp[i-1][size-1-j] * state[j] % MOD;
    REP(j, size-1) dp[i][j+1] = (dp[i][j] + dp[i][j+1]) % MOD;
  }
  cout << dp[K-1][size-1] << endl;
}

Measured memory_bytes: 53792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int ans = 0;
        int outlet = 1;
        while (outlet < b) {
            outlet--;
            outlet += a;
            ans++;
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 35576
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

// #include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

ll n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll tot = 0;
    ll len = 1;
    ll cur_pow = 26;
    while (tot + cur_pow < n) {
        len++;
        tot += cur_pow;
        cur_pow *= 26;
    }

    ll index = n - tot;
    // find the i^th string of length len

    string ans;
    for (int i = len - 1; i >= 0; i--) {
        //char = 'a' + (index) / 26^(i)
        cur_pow /= 26;
        ll shift = (index - 1) / cur_pow; //???
        // cout << "index: " << index << "\n";
        // cout << "shift: " << shift << "\n";
        index -= cur_pow * shift;
        ans += (char)('a' + shift);
    }
    cout << ans << "\n";

}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 3612
N, A, B = map(int, input().split())

if (B-A)%2 == 0:
    print((B-A)//2)
else:
    if A-1 < (N-B):
        ans = A
        B -= A
        A = 1
        ans += (B-A)//2
        print(ans)
    else:
        ans = N-B+1
        A += N-B+1
        B = N
        ans += (B-A)//2
        print(ans)


Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
heights = gets.split.map(&:to_i)

is_good = [true] * n
m.times{|i|
    a, b = gets.split.map{|it| it.to_i - 1}
    if ! (heights[a] < heights[b])
        is_good[b] = false
    end
    if ! (heights[b] < heights[a])
        is_good[a] = false
    end
}
puts is_good.count{|it| it}


Measured memory_bytes: 22528
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include <string.h>
#include <math.h>

using namespace std;


int n, a[200],c=0;

bool ne() {
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			a[i] /= 2;
		}
		else {
			return false;
		}
	}
	return true;
}


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

	while (ne())c++;

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	
		String s = sc.next();

      // スペース区切りの整数の入力
		
		// 出力
    s=s.replace("2017","2018");
		System.out.println(s);
	
      }
}

Measured memory_bytes: 23252
from operator import itemgetter
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC_list = []
BC_sorted = sorted(BC,key=itemgetter(1) ,reverse = True)

for i in BC_sorted:
    BC_list += [i[1]] * i[0]
    if len(BC_list) > N:
        break

Answer = 0
A += BC_list
ALL = sorted(A, reverse = True)

for i in range(N):
    Answer += ALL[i]
print(Answer)

Measured memory_bytes: 39160
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    CNT = 0
    ans = 0
    for c in S:
        if c == 'R':
            CNT += 1
        else:
            ans = max(ans,CNT)
            CNT = 0

    ans = max(ans,CNT)
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector< int > A(N), B(M);
  cin >> A >> B;
  int64 ret = 0, sum = 0;
  vector< int64 > S(M + 1);
  for(int i = 0; i < M; i++) {
    S[i + 1] = S[i] + B[i];
  }
  for(int i = 0; i <= N; i++) {
    if(i > 0) sum += A[i - 1];
    if(sum <= K) {
      int pos = upper_bound(begin(S), end(S), K - sum) - begin(S) - 1;
      chmax(ret, i + pos);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
#define dout if(debug) cout
const int maxn = 1e5+1;
typedef long long ll;
using namespace std;
const ll MOD =1e9+7;
int a[1000];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i)
        cin>>a[i];
    int ans=0;
    for(int i=1; i<=n;){
        int val=a[i];
        int j=i;

        while(j<=n && a[j]==val)
            ++j;
        int col=j-i;
        ans+=col/2;
        i=j;
    }
    cout<<ans;
}


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

int n,k;
long long X[50],Y[50],X2[50],Y2[50],ans;

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>X[i]>>Y[i];
		X2[i]=X[i];
		Y2[i]=Y[i];
	}
	sort(X2,X2+n);
	sort(Y2,Y2+n);
	
	ans=(X2[n-1]-X2[0])*(Y2[n-1]-Y2[0]);
	
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			for(int ii=0;ii<n-1;ii++){
				for(int jj=ii+1;jj<n;jj++){
					int cnt=0;
					for(int q=0;q<n;q++){
						if(X2[i]<=X[q] and X[q]<=X2[j] and Y2[ii]<=Y[q] and Y[q]<=Y2[jj]){
							cnt++;
						}
					}
					if(cnt>=k){
						ans=min(ans,(X2[j]-X2[i])*(Y2[jj]-Y2[ii]));
					}
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

uint32_t calc_digit(uint32_t n, uint32_t base) {
  if (n == 0) return 0;
  return calc_digit(n / base, base) + 1;
}

uint32_t pow(uint32_t base, uint32_t exp) {
  if (exp == 0) return 1;
  return pow(base, exp - 1) * base;
}

int main() {
  uint32_t N = 0;
  std::cin >> N;

  const uint32_t base = 10;
  uint32_t count = 0;
  int32_t digit = calc_digit(N, base);
  if (digit % 2) {
    count += N - pow(base, digit - 1) + 1;
    digit--;
  }
  digit--;
  while (digit != -1) {
    count += pow(base, digit - 1) * 9;
    digit -= 2;
  }

  std::cout << count << std::endl;

  return 0;
}

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

using namespace std;


int main()
{
	string bun;
	cin >> bun;

	int i = 0,j = 1,hantei=0;

	while (bun[i] != '\0')
	{
		j = i + 1;
		while (bun[j] != '\0')
		{
			if (bun[i] == bun[j])
			{
				hantei = 1;
				break;
			}
			j++;
		}

		if (hantei == 1)
		{
			cout << "no" << endl;
			break;
		}
		i++;
	}

	if (hantei == 0) cout << "yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> c(h);
  rep(i,h)cin>>c[i];
  int ans=0;
  for(int bi=0;bi<(1<<h);bi++){
    for(int bj=0;bj<(1<<w);bj++){
      int cnt=0;
      for(int i=0;i<h;i++){
        if(bi & (1<<i))continue;
        for(int j=0;j<w;j++){
          if(bj & (1<<j))continue;
          if(c[i][j]=='#')cnt++;
        }
      }
      if(cnt==k)ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  pair<int,int> p1,p2;
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int dx=x1-x2;
  int dy=y1-y2;
  p1.first=x2+dy;
  p1.second=y2-dx;
  p2.first=x1+dy;
  p2.second=y1-dx;
  cout<<p1.first<<endl;
  cout<<p1.second<<endl;
  cout<<p2.first<<endl;
  cout<<p2.second<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
import collections

S =input()
char = collections.Counter(S)
char_bas = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(char_bas)):
    if char_bas[i] in char:
        if char_bas[i] == 'z':
            print('None')
            break
        continue
    else:
        print(char_bas[i])
        break

Measured memory_bytes: 3572
#include <cstdio>
void swap(int *a,int *b) {
    int s;
    s = *a;
    *a = *b;
    *b = s;
}

int main() {
    int a;
    scanf("%d",&a);
    int n[a];
    for(int i=0;i<a;i++) {
        scanf("%d",&n[i]);
    }
    for(int i=a-1;i>=0;i--) {
        if(i != a-1) {
            printf(" ");
        }
        printf("%d",n[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2692
#include <stdio.h>
 
int main(int argc, char const *argv[]) {
  int x=0,y=0;
  int ans=0;
  scanf("%d",&x);
  int yama[x];
  for (int i = 0; i < x; i++) {
    scanf("%d",&yama[i]);
  }
  for (int i = 0; i < x; i++) {
    if (yama[i]>=y) {
      ans++;
      y=yama[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 7;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    for &(_, j) in cands.iter().take(2) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2336
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n;
    cin>>n;
    VI a(n);
    rep(i,n) cin>>a[i];

    sort(all(a));
    reverse(all(a));

    int cnt=0;
    ll ans=1;
    for(int i=0;i<n-1;i++){
        //cout<<a[i]<<endl;
        if(a[i]==a[i+1]){
            ans*=a[i];
            i+=1;
            cnt++;
        }
        if(cnt==2){
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}



Measured memory_bytes: 640
#include <stdio.h>
 
using namespace std;
 
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x >= r && x <= W-r) && (y >= r && y <= H-r))
        printf("Yes\n");
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 2600
import java.util.Scanner;

public class Main {
	public static void main(String[]args){

		//????????£????????????
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		//?????¶??? a??????b???????????§??????
		if(a < b){
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26276
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)



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

    int cnt = 0;
    rep(i, n-2){
        //cout << s.substr(i, 3) << endl;
        if(s.substr(i, 3) == "ABC") cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
k=[]
ans=0
for i in range(400005):
  k.append(0)
for i in range(n):
  if i-a[i]>=0:
    ans+=k[i-a[i]]
  if a[i]+i<400005:
    k[a[i]+i]+=1
print(ans)

Measured memory_bytes: 32248
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
//--Container
//
typedef long long ll;
typedef pair<int,int> pi;

int n,dh,ar[100010],br[100010];
bool _ck(int tk){
	int i,j,k;ll rs=(ll)tk*ar[n-1];
	for(i=0;rs<dh&&i<n&&i<tk;++i){
		rs-=ar[n-1];rs+=br[n-i-1];
	}
	return rs>=dh;
};
void cl(){
	int i,j,k;scanf("%d %d",&n,&dh);
	for(i=0;i<n;++i)scanf("%d %d",&ar[i],&br[i]);
	sort(ar,ar+n),sort(br,br+n);
	int b=1,e=1e9,r=1e9,m;while(b<=e){
		m=(b+e)>>1;if(_ck(m))r=m,e=m-1;
		else
			b=m+1;
	}
	printf("%d\n",r);
};

int main(){
	cl();
	return 0;
};

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	rep(i, n) {
		int val; cin >> val;
		pairs.push_back({ val, i + 1 });
	}

	sort(ASC(pairs));

	rep(i, n) {
		cout << pairs[i].second << endl;
	}
}

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

const int MAX_N = 21;

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

  int V[MAX_N];
  int C[MAX_N];
  for (int i = 0; i < N ; i++) cin >> V[i];
  for (int i = 0; i < N ; i++) cin >> C[i];
  

  int sum = 0;
  for (int i = 0; i < N; i++) {
    int k = V[i] - C[i];
    if (k > 0) sum += k;
  }
  cout << sum << endl;
}


Measured memory_bytes: 384
M, D = map(int, input().split())

ans = 0
for m in range(1, M+1):
    for d in range(22, D+1):
        d1, d2 = d//10, d%10
        if d1 < 2 or d2 < 2: continue
        if d1*d2 == m:
            ans += 1

print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	final int B = 4;
	final int F = 3;
	final int R = 10;
	Scanner in =new Scanner(System.in);
	
	int[][][] room = new int[F][R][B];

	for(int k=0;k<B;k++){
	    for(int i=0; i<F; i++){
		for(int j=0; j<R; j++){
		    room[i][j][k]=0;
		}
	    }
	}

	int n = in.nextInt();
	for(int i=0;i<n;i++){
	    int b = in.nextInt();
	    int f = in.nextInt();
	    int r = in.nextInt();
	    int v = in.nextInt();
	    room[f-1][r-1][b-1]+= v;
	    
	}

	for(int k=0;k<B;k++){
	    if(k>0 && k<=B-1)System.out.println("####################");
	     for(int i=0; i<F; i++){
		for(int j=0;j<R;j++){
		    System.out.print(" "+room[i][j][k]);
		}
		System.out.println();
	    }
	}
    }
}



Measured memory_bytes: 29948
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l][r] += 1
for i in range(1, n + 1):
    for j in range(1, n + 1):
        ls[i][j] += ls[i - 1][j] + ls[i][j - 1] - ls[i - 1][j - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(ls[r][r] - ls[l - 1][r] - ls[r][l - 1] + ls[l - 1][l - 1])

Measured memory_bytes: 54748
n = int(input())
a = [int(input()) for i in range(n)]

a.sort()

ans = 0

for i in range(n):
    if n%2==0:
        if i<n//2-1:
            ans-=a[i]*2
        if i==n//2-1:
            ans-=a[i]
        if i==n//2:
            ans+=a[i]
        if i>n//2:
            ans+=a[i]*2
    else:
        if i<n//2-1:
            ans-=a[i]*2
        if i>n//2+1:
            ans+=a[i]*2

if n%2==1:
    if a[n//2+1]-a[n//2]>a[n//2]-a[n//2-1]:
        ans += a[n//2+1]*2-a[n//2]-a[n//2-1]
    else:
        ans += a[n//2+1]+a[n//2]-a[n//2-1]*2

print(ans)

Measured memory_bytes: 7480
(function main(){
  let lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  let [n, k] = lines.shift().split(' ').map(Number);
  let w = lines.map(Number);

  const canAllStack = (p) => {
    let cnt = 0;
    let sum = 0;
    for (let i = 0; i < k; i++) {
      sum = 0;
      while (sum + w[cnt] <= p) {
        sum += w[cnt++]
        if (cnt === n) return n;
      }
    }
    return cnt;
  };

  let mid, left = 0, right = 1e9;
  while (right - left > 1) {
    mid = Math.floor((right + left) / 2);
    if (canAllStack(mid) >= n) right = mid;
    else left = mid;
  }
  console.log(right);
})();



Measured memory_bytes: 29216
#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++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, t;
  cin >> n >> t;
  vi a(n);
  rep(i,n) cin >> a[i];
  int mn = a[0];
  int mx = 0;
  int ans = 0;
  REP(i,n) {
    if(a[i] > mn) {
      if(mx == a[i]-mn) ans++;
      else if(mx < a[i]-mn) {
        mx = a[i]-mn;
        ans = 1;
      }
    }
    else {
      mn = a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#pragma GCC optmize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int issqrt(int d) {
	for (int i = 0; i * i <= d; ++i) {
		if (i * i == d) return i;
	}
	return 0;
}

bool solve() {
	int h, w;
	cin >> h >> w;
	if (h == 0 && w == 0) return false;
	int d = h * h + w * w;
	for (int i = h + 1; i * i < d; ++i) {
		int tmp = d - i * i;
		int sq;
		if (sq = issqrt(tmp)) {
			if (sq <= i) continue;
			cout << i << " " << sq << endl;
			return true;
		}
	}
	while (true) {
		++d;
		for (int i = 1; i * i < d; ++i) {
			int w_ = issqrt(d - i * i);
			if (w_) {
				if (w_ <= i) continue;
				cout << i << " " << w_ << endl;
				return true;
			}
		}
	}
}

int main() {
	while (solve());
	return 0;
}


Measured memory_bytes: 3084
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace AtCoder_Beginner_Contest_131
{
    class Program
    {
        //参照(http://drken1215.hatenablog.com/entry/2019/06/23/004700)
        class UnionFind
        {
            int[] par;
            public UnionFind(int n)
            {
                init(n);
            }
            public void init(int n)
            {
                par = new int[n];
                for (var i = 0; i < n; ++i)
                { par[i] = -1; }
            }
            public int root(int x)
            {
                if (par[x] < 0) return x;
                else return par[x] = root(par[x]);
            }
            public bool issame(int x, int y)
            {
                return root(x) == root(y);
            }
            public bool merge(int x, int y)
            {
                x = root(x); y = root(y);
                if (x == y) return false;
                if (par[x] > par[y])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                par[x] += par[y];
                par[y] = x;
                return true;
            }
            public int size(int x)
            {
                return -par[root(x)];
            }
        }
        const int MAX = 110000;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {

            var N = Sarray()[0];
            UnionFind uf = new UnionFind(MAX * 2);
            var x = new List<int>();
            var y = new List<int>();
            for (var i = 0; i < N; ++i)
            {
                var xy = Sarray();
                x.Add((int)xy[0]);
                y.Add((int)xy[1]);
                uf.merge(x[i], y[i] + MAX);
            }
            var mx = new long[MAX * 2];
            var my = new long[MAX * 2];
            for (var i = 0; i < MAX; ++i) { mx[uf.root(i)]++; }
            for (var i = MAX; i < MAX * 2; ++i) { my[uf.root(i)]++; }
            long res = 0;
            for (var r = 0; r < MAX * 2; ++r) res += mx[r] * my[r];
            WriteLine(res - N);
        }
    }
}

Measured memory_bytes: 22072
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    vector<int> a(10),b(10);
    REP(i,10) cin>>a[i];
    REP(i,10) cin>>b[i];
    sort(ALL(a));
    sort(ALL(b));
    cout<<a[9]+a[8]+a[7]<<" "<<b[9]+b[8]+b[7]<<endl;
    return 0;
}

Measured memory_bytes: 3020
using System;
using System.Linq;

class D
{
    static void Main()
    {
        var s = Console.ReadLine();
        var b = s.Select((c, i) => s[i + (c == 'L' ? -1 : 1)] == c).ToArray();
        var a = Enumerable.Repeat(1, s.Length).ToArray();

        for (var i = 0; i < s.Length; i++)
        {
            if (s[i] == 'R' && b[i])
            {
                a[i + 2] += a[i];
                a[i] = 0;
            }
        }
        for (var i = s.Length - 1; i >= 0; i--)
        {
            if (s[i] == 'L' && b[i])
            {
                a[i - 2] += a[i];
                a[i] = 0;
            }
        }
        Console.WriteLine(string.Join(" ", a));
    }
}


Measured memory_bytes: 14688
X = int(input())

for a in range(-1000,1001) :
    powa = pow(a,5)
    for b in range(-1000,1001) :
        powb = pow(b,5)
        # print(a,b,powa,powb)
        if (powa - powb == X) :
            print(a,b)
            exit()
        

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    cout << ((n + m - 3) / (m - 1)) << endl;
    return 0;
}


Measured memory_bytes: 764
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=next[i])

using namespace std;

const int INF=1<<30;

const int maxn=100000+10;

int a[maxn],t[maxn];

int n;
int C[maxn*2];

#define lowbit(x) ((x)&(-(x)))
inline void updata(int pos,int val){
	for(int i=pos;i<=n*3;i+=lowbit(i)) C[i]+=val;
}

inline int query(int pos){
	int ret=0;
	for(int i=pos;i;i-=lowbit(i)) ret+=C[i];
	return ret;	
}

typedef long long ll;

inline bool check(int mid)
{
	rep(i,1,2*n) C[i]=0;
	ll x=(1ll*n*(n+1)/2)/2+1,rk=0;
	int sum=0;
	
	updata(n+1,1);
	rep(i,1,n)
	{
		sum+= a[i]<mid?1:-1;
		rk+=query(sum+n);
		updata(sum+n+1,1);
	}
	
	return rk+1<=x;
}

int main()
{
	cin>>n;
	rep(i,1,n) scanf("%d",a+i),t[i]=a[i]; 
	sort(t+1,t+n+1);
	
	int l=1,r=n,mid,ans;
	
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(t[mid])) ans=t[mid],l=mid+1;
		else r=mid-1;	
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 1920
n, a, b, k = map(int, input().split())

def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(n+1):
    x = a*i
    y = k-x
    if y < 0:
        continue
    if y%b == 0:
        j = y//b
        ans += cmb1(n, i, mod)*cmb1(n, j, mod)
print(ans%mod)


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int a[5];
    for (int i = 0; i < 5;i++)
    {
        cin >> a[i];
        if(a[i]==0)
        {
            cout << i + 1;
            break;
        }
    }
        return 0;
}




Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  long a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b || b <= c && c <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;
int main()
{
    int n;
    scanf("%d", &n);
    VI a(n+1);
    for(int i = 1; i < n; ++i){
        int x;
        scanf("%d", &x);
        a[x]++;
    }
    for(int i = 1; i <= n; ++i) printf("%d\n", a[i]);
    return 0;
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
 ll n;
 cin>>n;
 ll a[n+1];
 for(int i=1;i<=n;i++){
     ll p;
     cin>>p;
     a[i]=p;
     
 }
 
 ll ans=0;
 for(int i=1;i<=n;i++){
     ans+=a[i];
     ans-=i;
 }
 
 cout<<ans<<endl;
 
}


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

int getBits(int l) {
	int cnt = 0;
	while (l) {
		cnt++;
		l >>= 1;
	}
	return cnt;
}

void solve() {
	int l;
	cin >> l;

	int n = getBits(l), cnt = 0;
	vector<vector<int> > res;
	for (int i = 1; i < n; i++) {
		res.push_back({i, i + 1, 0});
		res.push_back({i, i + 1, 1 << (i - 1)});
	}
	cnt += 1 << (n - 1);

	for (int i = 0; i < n - 1; i++)
		if (l & (1 << i)) {
			res.push_back({i + 1, n, cnt});
			cnt += 1 << i;
		}

	cout << n << " " << res.size() << endl;
	for (auto x: res)
		cout << x[0] << " " << x[1] << " " << x[2] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	solve();
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto size = readln.chomp.to!int;
  auto lucky = cast(byte[])readln.chomp;
  lucky[] -= '0';

  void solve() {
    int count;
    foreach(x; 0..10) foreach(y; 0..10) foreach(z; 0..10) {
      if (!lucky.canFind(x)) continue;
      auto after = lucky.findSplitAfter([x]);
      if (!after[1].canFind(y)) continue;
      after = after[1].findSplitAfter([y]);
      if (!after[1].canFind(z)) continue;
      count++;
    }
    writeln(count);
  }

  solve();
}


Measured memory_bytes: 380
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

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

ll N;

void input() {
    cin >> N;
}

void putlist(vector<ll>& list) {
    cout << list.size() << ' ';
    for (ll v : list) {
        cout << v << ' ';
    }
    cout << endl;
}

void solve() {
    ll n = 1;
    ll k = 1;
    bool able = false;
    while (n <= 2 * N) {
        if (n == 2 * N) {
            able = true;
            break;
        }
        n *= k + 1;
        if (k > 1)
            n /= k - 1;
        k++;
    }
    if (!able) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    
    if (N == 1) {
        cout << 2 << endl;
        cout << 1 << ' ' << 1 << endl;
        cout << 1 << ' ' << 1 << endl;
        return;
    }
    
    k--;
    vector<ll> tri[k];
    ll num = 1;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j <= i; j++) {
            tri[i].push_back(num++);
        }
    }
    cout << k + 1 << endl;
    vector<ll> list(k);
    for (int i = 0; i < k; i++) {
        list[i] = tri[i].front();
    }
    putlist(list);
    for (int i = 0; i < k; i++) {
        list[i] = tri[i].back();
    }
    putlist(list);
    for (int i = 0; i < k; i++) {
        list[i] = tri[k - 1][i];
    }
    putlist(list);
    for (int i = 1; i < k - 1; i++) {
        for (int j = 0; j < k; j++) {
            if (j <= i) {
                list[j] = tri[i][j];
            } else {
                list[j] = tri[j][i];
            }
        }
        putlist(list);
    }
}


int main() {
    input();
    solve();
    
    return 0;
}



Measured memory_bytes: 2560
n,k,c=map(int,input().split())
s=input()

l2 = [float("inf")]*n

cnt2 = k
i = n-1
while cnt2 != 0:
    if s[i] == "o":
        l2[i] = cnt2
        i -= c + 1
        cnt2 -= 1
    else:
        i -= 1

cnt1 = 0
i = 0
while cnt1 < k:
    if s[i] == "o":
        if l2[i] == cnt1 + 1:
            print(i+1)
        i += c + 1
        cnt1 += 1
    else:
        i += 1


Measured memory_bytes: 12688
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef std::pair<int,int> P;
#define mk std::make_pair
#define fr first
#define sc second
inline int in()
{
	int k=0;char ch=gt;bool p=1;
	while(ch<'-')ch=gt;if(ch=='-')ch=gt,p=0;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return p?k:-k;
}
const int N=2e5+5;
int fa[N],head[N],to[N<<1],nxt[N<<1],cnt,n,m;
inline void add(int u,int v)
{
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline int abs(int x){return x<0?-x:x;}
namespace w1
{
	int f[N];ll ans;
	void dfs(int u,int pa=0,int d=1)
	{
		f[u]=d&1?1:-1;
		for(int i=head[u];i;i=nxt[i])
			if(to[i]!=pa)dfs(to[i],u,d+1),f[u]+=f[to[i]];
		if(u!=1)ans+=abs(f[u]);
	}
	int work()
	{
		for(int i=2;i<=n;++i)add(in(),in());
		ans=0;dfs(1);
		if(f[1])puts("-1");
		else printf("%lld\n",ans);
		return 0;
	}
}
int f[N],dep[N],st[N],tot;
void dfs(int u,int pa=0,int d=1)
{
	f[u]=d&1?1:-1;dep[u]=d,fa[u]=pa;
	for(int i=head[u];i;i=nxt[i])
		if(to[i]!=pa)dfs(to[i],u,d+1),f[u]+=f[to[i]];
}
int main()
{
	n=in(),m=in();if(n&1)return puts("-1"),0;
	if(m==n-1)return w1::work();
	int Eu,Ev;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=n;++i)
	{
		int u=in(),v=in();
		if(find(u)==find(v)){Eu=u,Ev=v;continue;}
		fa[find(u)]=find(v);add(u,v);
	}
	dfs(Eu);
	if(dep[Ev]&1)
	{
		if(f[Eu]&1)return puts("-1"),0;
		ll ans=0;int res=f[Eu]>>1,u=Ev;
		while(u)f[u]-=res,u=fa[u];
		for(int i=1;i<=n;++i)ans+=abs(f[i]);
		printf("%lld\n",ans);
	}
	else
	{
		if(f[Eu])return puts("-1"),0;
		int u=Ev;ll ans=0;
		while(u!=Eu)st[++tot]=f[u],u=fa[u];
		std::sort(st+1,st+tot+1);
		int x=st[tot+1>>1];u=Ev;
		while(u)f[u]-=x,u=fa[u];
		for(int i=1;i<=n;++i)ans+=abs(f[i]);
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 10880
import sys

read = sys.stdin.read


def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


N, *C = map(int, read().split())
mod = 10 ** 9 + 7

C.sort(reverse=True)
n = mod_pow(4, N - 1, mod)

answer = 0

for i, c in enumerate(C, 2):
    answer += i * c

answer *= n
answer %= mod

print(answer)


Measured memory_bytes: 25124
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str1,str2;
    cin>>n;
    vector<ll> v(n+1);
    vector<ll> w(n);
    rep(i,n+1)   cin >> v[i];
    rep(i,n)   cin >> w[i];
    rep(i,n){
    if(v[i]>w[i]){
        sum+=w[i];
        v[i]=v[i]-w[i];
        w[i]=0;
    }else{
        sum+=v[i];
        w[i]-=v[i];
        v[i]=0;
    }
    if(v[i+1]>w[i]){
        sum+=w[i];
        v[i+1]=v[i+1]-w[i];
        w[i]=0;
    }else{
        sum+=v[i+1];
        w[i]-=v[i+1];
        v[i+1]=0;
    }
    }
    cout<<sum<<endl;
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int num(char c) { return c - '0'; }
int main() {
source:
    string n;
    ll k;
    cin >> n >> k;
    int len = n.length();
    ll x[len][3], y[len];
    x[0][1] = num(n[0]) - 1;
    x[0][2] = 0;
    x[0][3] = 0;
    y[0] = 1;
    repd(i, 1, len) {
        int temp = num(n[i]);
        x[i][1] = x[i - 1][1] + 9;
        x[i][2] = x[i - 1][2] + x[i - 1][1] * 9;
        x[i][3] = x[i - 1][3] + x[i - 1][2] * 9;
        if (temp != 0) {
            y[i] = y[i - 1] + 1;
            if (y[i - 1] == 1) {
                x[i][1] += 1;
                x[i][2] += temp - 1;
            } else if (y[i - 1] == 2) {
                x[i][2] += 1;
                x[i][3] += temp - 1;
            } else if (y[i - 1] == 3) {
                x[i][3] += 1;
            }
        } else {
            y[i] = y[i - 1];
        }
    }

    int last = y[len - 1];
    if (last <= 3) {
        x[len - 1][last]++;
    }

    cout << x[len - 1][k] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int f(int x) {
    int r = 1;
    rep(i, 5) {
        r *= x;
    }
    return r;
}

int main() {
    int x;
    cin >> x;
    for (int a = -120; a <= 120; a++) {
        for (int b = -120; b <= 120; b++) {
            if (f(a) - f(b) == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3608
import sys
input = sys.stdin.readline

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

cnt = 0
dice = [(i+1)/2 for i in p]

ans = sum(dice[:k])
exp = sum(dice[:k])

for i in range(k, n):
    exp = exp-dice[i-k]+dice[i]
    ans = max(ans, exp)
print(ans)


Measured memory_bytes: 25632
#include <stdio.h>

int max(int a, int b){
	if(a>b){
		return a;
	}
	return b;
}

int min(int a, int b){
	if(a>b){
		return b;
	}
	return a;
}

int main(){
	int H;
	scanf("%d",&H);
	int W;
	scanf("%d",&W);
	char c;
	char d;
	char l[1001][1001];
	int i;
	int j;
	for(i=1;i<=H;i++){
		scanf("%c",&d);
		for(j=1;j<=W;j++){
			scanf("%c",&c);
			l[i][j]=c;
		}
	}
	int m;
	m=H+W;
	int p[1001][1001];
	int q[1002][1001];
	int r[1001][1002];
	int s[1002][1002];
	for(i=1;i<=H;i++){
		p[i][0]=m;
		q[i][W+1]=m;
		r[i][0]=m;
		s[i][W+1]=m;
	}
	for(j=1;j<=W;j++){
		p[0][j]=m;
		q[0][j]=m;
		r[H+1][j]=m;
		s[H+1][j]=m;
	}
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			if(l[i][j]=='#'){
				p[i][j]=0;
			}else{
				p[i][j]=min(p[i-1][j],p[i][j-1])+1;
			}
		}
	}
	for(i=1;i<=H;i++){
		for(j=W;j>=1;j--){
			if(l[i][j]=='#'){
				q[i][j]=0;
			}else{
				q[i][j]=min(q[i-1][j],q[i][j+1])+1;
			}
		}
	}
	for(i=H;i>=1;i--){
		for(j=1;j<=W;j++){
			if(l[i][j]=='#'){
				r[i][j]=0;
			}else{
				r[i][j]=min(r[i+1][j],r[i][j-1])+1;
			}
		}
	}
	for(i=H;i>=1;i--){
		for(j=W;j>=1;j--){
			if(l[i][j]=='#'){
				s[i][j]=0;
			}else{
				s[i][j]=min(s[i+1][j],s[i][j+1])+1;
			}
		}
	}
	int n[1001][1001];
	int ans;
	ans=0;
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			n[i][j]=min(p[i][j],q[i][j]);
			n[i][j]=min(n[i][j],r[i][j]);
			n[i][j]=min(n[i][j],s[i][j]);
			ans=max(ans,n[i][j]);
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 16768