akhauriyash/Code-Regression huggingface dataset:
N,K = map(int, input().split())
P = []
for _ in range(N):
  a,b = map(int, input().split())
  P.append((a,b))
  
ans = 5 * 10 ** 18

def solve(xl,xr,yl,yr):
  xm, xM = min(xl[0], xr[0]), max(xl[0], xr[0])
  ym, yM = min(yl[1], yr[1]), max(yl[1], yr[1])
  cnt = 0
  for k in range(N):
    p,q = P[k]
    if xm <= p <= xM and ym <= q <= yM:
      cnt += 1
  #print(xm, xM, ym, yM, cnt)
  return cnt >= K
    
def calc(xl,xr,yl,yr):
  return abs(xr[0] - xl[0]) * abs(yr[1] - yl[1])
  
for i in range(N):
  for j in range(i+1,N):
    for k in range(N):
      for l in range(k+1,N):
        if solve(P[i], P[j], P[k], P[l]):
          wk = calc(P[i], P[j], P[k], P[l])
          #rint(i,j,k,l,wk)
          ans = min(ans, wk)
      
print(ans)

Measured memory_bytes: 79828
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll a, v, b, w; cin >> a >> v >> b >> w;
    ll t; cin >> t;
    ll di = abs(a - b);
    ll ds = t*(v - w);
    if(ds >= di){
        prt("YES");
    }else{
        prt("NO");
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  s[m-1]+=32;
  cout << s << endl;
  return 0;
}


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

/**
 *
 * @author ena000078
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        long h[] = new long[N];
        
        for(int i=0;i<N;i++){
            h[i] = sc.nextLong();
        }
        
        Arrays.sort(h);
        
        long iMin = 1;
        long iMax = h[h.length-1];
        
        while(iMin < iMax){
            long iMid = (iMax + iMin)/2;
            
            if(enough(h, A, B, iMid)){
                iMax = iMid;
            }else{
                iMin = iMid;
            }
            if((iMax - iMin) == 1){
                break;
            }
        }
        System.out.println(iMax);
    }
    
    static boolean enough(long[] h, long A, long B, long T){
        boolean rtn = true;
        int count = 0;
        long addDmg = A - B;
        
        for(int i=0;i<h.length;i++){
            long tmp = h[i];
            tmp = tmp - (B * T);
            if (tmp > 0){
                double tCnt = (double)tmp / (double)addDmg;
                count += Math.ceil(tCnt);
            }
        }
        if(count > T){
            rtn = false;
        }
        return rtn;
    }

}

Measured memory_bytes: 50460
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int g[]={-1,0,2,0,1,0,1,0,0,1,0,1,0};
  int x,y;
  cin>>x>>y;
  cout<<(g[x]==g[y]?"Yes":"No")<<endl;
  return 0;
}


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

int main()
{
    int n, m, c, b[21], a[21][21], i, j, s, k=0;
    cin>>n>>m>>c;
    for(i=1; i<=m; i++)
        cin>>b[i];
    for(i=1; i<=n; i++)
    {
        s=c;
        for(j=1; j<=m; j++)
            cin>>a[i][j];
        for(j=1; j<=m; j++)
            s+=a[i][j]*b[j];
        if(s>0)
            k++;
    }
    cout<<k;
}


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

using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define FOR(i,b,n) for(ll i=(b); i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define TEN(x) ((ll)1e##x)

template<typename T> inline string join(const vector<T>& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); }


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

#define EPS (1e-10)
#define NEXT(x, i) (x[(i + 1) % x.size()])

template<class T> using CR = const T &;
using P = complex<ld>;
using G = vector<P>;

int sgn(ld a, ld b = 0) {
	if (a > b + EPS) return 1;
	if (a < b - EPS) return -1;
	return 0;
}

ld dot(P a, P b) { return real(conj(a)*b); }
ld cross(P a, P b) { return imag(conj(a)*b); }

int ccw(P a, P b, P c) {
	b -= a;
	c -= a;
	if (sgn(cross(b, c))) return sgn(cross(b, c)); // clockwise or counter clockwise
	if (sgn(dot(b, c)) == -1) return 2;            // c--a--b
	if (sgn(norm(b), norm(c)) == -1) return -2;    // a--b--c
	return 0;                                      // a--c--b
}
bool is_convex(CR<G> g) {
	REP(i, g.size()) if (ccw(g[(i+g.size()-1) % g.size()], g[i], g[(i + 1) % g.size()]) == -1) return false;
	return true;
}


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

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	ll n; cin >> n;

	G g(n);
	REP(i,n){
		ld x, y;
		cin >> x >> y;
		g[i] = { x, y };
	}
	cout << is_convex(g) << endl;

	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> vs(2, vector<int>(100000+1, 0));
    for(int i=0; i<n; ++i){
        int v;
        cin >> v;
        ++vs[i%2][v];
    }

    int max_1[2]={0, 0};
    int max_v[2];
    for(int vi=0; vi<2; ++vi){
        for(int i=1; i<=100000+1; ++i){
            if(vs[vi][i]>max_1[vi]){
                max_1[vi]=vs[vi][i];
                max_v[vi]=i;
            }
        }
    }

    if(max_v[0]!=max_v[1]){
        cout << n-(max_1[0]+max_1[1]) << endl;
    } else{
        int max_2[2]={0, 0};
        for(int vi=0; vi<2; ++vi){
            for(int i=1; i<=100000+1; ++i){
                if(i==max_v[vi]) continue;
                if(vs[vi][i]>max_2[vi]){
                    max_2[vi]=vs[vi][i];
                }
            }
        }
        int t=max(max_1[0]+max_2[1], max_1[1]+max_2[0]);
        cout << n-t << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

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

int main(){
    char s[101];
    cin >> s;
    int len=strlen(s),ans=0;
    rep(i,len/2){
        if(s[i] != s[len-i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(0, k*2)]
a = query[1::2]
sunuke = [0] * n

for a in query[1::2]:
    for s in a:
        sunuke[s-1] += 1
print(sunuke.count(0))


Measured memory_bytes: 9188
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

int main()
{

    int k,a,b,flag=0;
    scanf("%d %d %d",&k,&a,&b);

    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag=1;
        }
    }

    if(flag==1)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");
    }
    

    return 0;
}

Measured memory_bytes: 1664
n = int(input())
s = input()
a = s.split()

def value(a, i):
    return int(a[i][-1])

def isstable(s, a, n):
    for i in range(n - 1):
        if value(a, i) == value(a, i + 1):
            v1 = s.index(a[i])
            v2 = s.index(a[i + 1])
            if v1 > v2:
                return "Not stable"
    return "Stable"

for i in range(n - 1):
    for j in range(i + 1, n)[::-1]:
        if value(a, j) < value(a, j - 1):
            a[j], a[j - 1] = a[j - 1], a[j]
print(" ".join(a))
print(isstable(s.split(), a, n))

a = s.split()

for i in range(n - 1):
    minj = i
    for j in range(i + 1, n):
        if value(a, j) < value(a, minj):
            minj = j
    a[i], a[minj] = a[minj], a[i]
print(" ".join(a))
print(isstable(s.split(), a, n))


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

def main():
    N = int(input())
    a = list(map(int, input().split()))

    dic = {}
    tmp = 0
    for i in range(N):
        if a[i] in dic:
            dic[a[i]] += 1
            tmp += 1
        else:
            dic[a[i]] = 1
    
    print(max(0, N - tmp - int(tmp&1)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 18336
#include <iostream>

#define max(a, b) ((a) > (b))? (a):(b)

using namespace std;

int main() {
    long long N, K; cin >> N >> K;
    long long cnt = 0;
    if(K == 0) {cout << N * N << endl; return 0;}
    for(int b=K+1; b<=N; b++ ) {
        cnt += (b - K) * (N / b);
        cnt += max(0, (N % b) - K + 1);
    }
    cout << cnt << endl;
}


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

struct edge{long to,cost;};
typedef pair<long,long> P;
 
long V;
vector<edge> g[100100];
long d[100100];
long inf = 2000000000000007;
 
void dijkstra(long s){
  priority_queue<P,vector<P>,greater<P>> que;
  for(long i = 0;i <= V;i++){
    d[i] = inf;
  }
  d[s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();
    que.pop();
    long v = p.second;
    if(d[v] < p.first) continue;
    for(long i = 0;i < g[v].size();i++){
      edge e = g[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  for(long i = 0;i < V-1;i++){
    edge e;
    long a;
    cin >> a >> e.to >> e.cost;
    edge f;
    f.to = a;
    f.cost = e.cost;
    g[a].push_back(e);
    g[e.to].push_back(f);
  }
  long q,k;
  cin >> q >> k;
  dijkstra(k);
  long x[q],y[q];
  for(long i = 0;i < q;i++){
    cin >> x[i] >> y[i];
    cout << d[x[i]] + d[y[i]] << endl;
  }
}

Measured memory_bytes: 11520
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split("\n")
        .skip(1)
        .map(|x| {
            let t = x.split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<_>>();
            //t-x-y
            (t[0], t[1], t[2])
        })
        .collect::<Vec<_>>();

    let mut now_t = 0;
    let mut now_x = 0;
    let mut now_y = 0;
    for (next_t, next_x, next_y) in list {
        for _ in 0..(next_t - now_t) {
            if next_x > now_x {
                now_x += 1;
            } else if next_x < now_x {
                now_x -= 1;
            } else if next_y > now_y {
                now_y += 1;
            } else {
                now_y -= 1;
            }
            now_t += 1;
        }
        if (next_t, next_x, next_y) != (now_t, now_x, now_y) {
            return "No".to_string();
        }
    }
    return "Yes".to_string();
}

#[test]
fn test() {
    let tests = vec![
        ("2\n3 1 2\n6 1 1", "Yes"),
        ("1\n2 100 100", "No"),
        ("2\n5 1 1\n100 1 1", "No"),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> as(N + 2, 0);
  vector<int> vs(N + 2, 0);
  for(int i = 1; i <= N; ++i) {
    cin >> as[i];
  }
  for(int i = 1; i <= N + 1; ++i) {
    vs[i] = vs[i - 1] + abs(as[i] - as[i - 1]);
  }
  vector<int> rs(N + 1, 0);
  for(int i = 1; i <= N; ++i) {
    rs[i] = vs[i - 1] + (vs[N + 1] - vs[i + 1]) + abs(as[i + 1] - as[i - 1]);
  }
  for(int i = 1; i <= N; ++i) {
    cout << rs[i] << endl;
  }

  return 0;
}

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

using namespace std;

/* alias */
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

/* repetition */
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)

int main() {
    int n;
    double sum = 0.0;
    cin >> n;
    rep(i,n)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
        {
            sum += x;
        }
        else
        {
            sum += x * 380000.0;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int c=0;
	    if (N>=10) {
	    	c+=9;
	    	if (N>=1000) {
		    	c+=900;
		    	if (N>=100000) {
			    	c+=90000;
			    }else if(N>=10000){
			    	c+=N-9999;
			    }
		    }else if(N>=100) {
		    	c+=N-99;
		    }
	    }else {
	    	c+=N;
	    }
	   
        System.out.print(c);
//        if (c<=2) {
//        	System.out.println("YES");
//        }else {
//        	System.out.println("NO");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

N = int(input())
a_list = list(map(int, input().split()))

cnt = 0
min_a  = 10 ** 9
for i in range(N):
  min_a  =  min(min_a,a_list[i])
  if min_a >= a_list[i]:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 24436
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
s = sum(a) - a[0]
for i in range(1, n):
    ans += a[i - 1] * s
    ans %= mod
    s -= a[i]
print(ans - s)


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

int main(){
	int a, b, c=0;
	cin >> a >> b;

	if(b<10) a=10*a+b;
	else if(b<100) a=100*a+b;
	else a=1000*a+b;

	for(int i=4;i<317;i++){
		if(i*i==a){
			c++;
			break;
		}
	}
	if(c!=0) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct state{
	int cap;
	int have;
	int move;
};
bool operator <(const state& left, const state& right){
	return left.move > right.move;
}
int main() {
	int n;
	while (cin >> n, n){
		vector<pair<int, int>> balloon(n + 1, { 0, 0 });
		REP(i, n){
			cin >> balloon[i + 1].first >> balloon[i + 1].second;//p,t
		}
		vector<vector<int>> dp(3,vector<int>(n,10000));
		bool clear = false;
		int ans;
		int ma = 1;
		priority_queue<state> P;//time,cap,having,move
		P.push({ 0, 0, 0 });
		while (!P.empty()){
			state st = P.top(); P.pop();
			if (st.cap == n){
				ans = st.move + balloon[st.cap].first;
				clear = true;
				break;
			}
			//?????£???????????????
			if (balloon[st.cap + 1].second >= balloon[st.cap].first*(st.have + 1) + balloon[st.cap + 1].first + balloon[st.cap].second)
				if (dp[0][st.cap]>st.move + balloon[st.cap + 1].first + balloon[st.cap].first){
					P.push({ st.cap + 1, 1, st.move + balloon[st.cap + 1].first + balloon[st.cap].first });
					dp[0][st.cap] = st.move + balloon[st.cap + 1].first + balloon[st.cap].first;
				}
			//??????????????´???
			if (st.have <= 2)
				if (balloon[st.cap + 1].second >= abs(balloon[st.cap + 1].first - balloon[st.cap].first)*(st.have + 1) + balloon[st.cap].second)
					if (dp[st.have ][st.cap]>st.move + abs(balloon[st.cap + 1].first - balloon[st.cap].first)){
						P.push({ st.cap + 1, st.have + 1, st.move + abs(balloon[st.cap + 1].first - balloon[st.cap].first) });
						dp[st.have ][st.cap] = st.move + abs(balloon[st.cap + 1].first - balloon[st.cap].first);
					}
			ma = max(ma, st.cap + 1);
		}
		if (clear){
			cout << "OK " << ans << endl;
		}
		else{
			cout << "NG " << ma << endl;
		}
	}
}

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007
def INT_(n): return int(n) - 1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n: int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

n, m, q = MI()
abcd = LLIN(q)

def main():
    data = list(range(1, m+1))
    arr = combinations_with_replacement(data, n)
    ans = 0
    for A in arr:
        tmp = 0
        for a,b,c,d in abcd:
            if A[b-1] - A[a-1] == c:
                tmp += d
            
        ans = max(ans, tmp)
    
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 72752
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String z = br.readLine();
		int c=0;
		for(int i=0;i<s.length();i++)
			if(s.charAt(i)!=z.charAt(i))
				c++;
		System.out.println(c);
	}
}

Measured memory_bytes: 36448
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	char str[5];
	memset(str, 0, 5);
	
	rewind(stdin);
	scanf("%s", str);


	int flg = 0;
	if (str[0] == str[1]) {
		flg = 1;
	}
	else if (str[1] == str[2]) {
		flg = 1;
	}
	else if (str[2] == str[3]) {
		flg = 1;
	}

	if (flg) {
		printf("Bad\n");
	}
	else {
		printf("Good\n");
	}

	rewind(stdin);
	getchar();
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 100000000000000
#define endl '\n'
ll power(ll a,ll b,ll m){ll ans=1;while(b){if(b&1) ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
ll pt[200005];
ll sz[200005];
void ms(ll v)
{
	pt[v]=v;
	sz[v]=1;
	return;
}
ll fs(ll v)
{
	if(pt[v]==v)
		return v;
	return pt[v]=fs(pt[v]);
}
void uns(ll a,ll b)
{
	a=fs(a);
	b=fs(b);
	if(a!=b)
	{
		if(sz[a]<sz[b])
			swap(a,b);
		pt[b]=a;
		sz[a]+=sz[b];
	}
	return;
}
int main()
{
	fastio;
	#ifdef gdb_18
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++)
		ms(i);
	for(ll i=1;i<=m;i++)
	{
		ll a,b;
		cin>>a>>b;
		uns(a,b);
	}
	ll mx=0;
	for(ll i=1;i<=n;i++)
	{
		if(pt[i]==i)
			mx=max(mx,sz[i]);
	}
	cout<<mx<<endl;
	return 0;	
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a % 2;
  d = b % 2;
  if(c==1&&d==1){
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
}

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

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

int needed_kaisu(long long a, long long N, long long *A) {
	int count = 0;
	for (long long i = 0; i < N; i++) {
		count += (A[i]+a-1) / a -1;
	}
	return count;
}


int main() {


	long long N,K,A[200100],ans,mem[200100];
	priority_queue<pair<long long, long long>> queue;

	long long max = 0;

	cin >> N >> K;
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
		if (max < A[i]) {
			max = A[i];
		}
	}

	long long lb = 0;
	long long ub = max;

	if (K == 0) {
		cout << max << endl;
		return 0;
	}


	while (1) {
		long long tmp = (lb + ub+1) / 2;
		if (needed_kaisu(tmp, N, A) <= K) {
			ub = tmp;
		}
		if (needed_kaisu(tmp, N, A) >= K+1) {
			lb = tmp;
		}
		if (ub <= lb+1) {
			break;
		}
	}

	cout << ub <<endl;

	cin >> N;

	return 0;


}



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

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b < 0)
    cout << "No" << endl;
  else if ((c - a - b) * (c - a - b) > 4 * a * b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a;
    int s[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    scanf("%d", &a);
  	printf("%d",s[a-1]);
    return 0;
}

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

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

    int min = 1000000;
    for(int i = 0; i < n; i++){
        int m;
        cin >> m;
        sum -= m;
        if(m < min){
            min = m;
        }
    }

    cout << n + (sum / min) << endl;

    return 0;
}

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

int left(int i, int n) {
    if (2*i <= n) {
        return 2*i;
    } else {
        return 0;
    }
}

int right(int i, int n) {
    if (2*i+1 <= n) {
        return 2*i+1;
    } else {
        return 0;
    }
}

int parent(int i) {
    if (i/2 > 0) {
        return i/2;
    } else {
        return 0;
    }
}

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

void maxHeapify(int i, int* A, int n) {
    int largest;
    int l = left(i, n);
    int r = right(i, n);
    if (A[l] > A[i]) {
        largest = l;
    } else {
        largest = i;
    }
    if (A[r] > A[largest]) {
        largest = r;
    }

    if (largest != i) {
        swap(i, largest, A);
        maxHeapify(largest, A, n);
    }
}

int main() {
    int H;
    std::cin >> H;
    int* tree = (int *)malloc((H+1)*sizeof(int));
    tree[0]=-2000000001;
    for (int i=1; i<=H; i++) {
        std::cin >> tree[i];
    }

    for (int i=H/2; i>0; i--) {
        maxHeapify(i, tree, H);
    }

    for (int i=1; i<=H; i++) {
        std::cout << " " << tree[i];
    }
    std::cout << "\n";

    return 0;
}


Measured memory_bytes: 5036
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int n, m;

int dijkstra(int s, int g, vector<bool> &city, vector<vector<P>> &G){
    vector<vector<int>> dist(n, vector<int>(m+10, 1e9));
    priority_queue<T, vector<T>, greater<T>> que;
    dist[s][m] = 0;
    que.push(T(0, s, m));

    while(!que.empty()){
        int cdist, cv, crest;
        tie(cdist, cv, crest) = que.top();
        que.pop();

        if(dist[cv][crest] < cdist) continue;

        if(city[cv] && crest < m){
            if(dist[cv][crest] + 1 < dist[cv][crest + 1]){
                dist[cv][crest + 1] = dist[cv][crest] + 1;
                que.push(T(dist[cv][crest + 1], cv, crest + 1));
            }
        }

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;

            if(crest - ncost < 0) continue;

            if(dist[cv][crest] + ncost < dist[nv][crest - ncost]){
                dist[nv][crest - ncost] = dist[cv][crest] + ncost;
                que.push(T(dist[nv][crest - ncost], nv, crest - ncost));
            }
        }
    }

    int ans = 1e9;
    for(int i=0; i<=m; i++){
        ans = min(ans, dist[g][i]);
    }

    return ans;
}

int main(){
    while(1){
        int l, k, a, h; cin>>n>>m>>l>>k>>a>>h;
        if(n == 0) return 0;
        vector<bool> city(n, false);
        for(int i=0; i<l; i++){
            int x; cin>>x;
            city[x] = true;
        }

        vector<vector<P>> G(n);
        for(int i=0; i<k; i++){
            int s, t, x; cin>>s>>t>>x;
            G[s].push_back(P(t, x));
            G[t].push_back(P(s, x));
        }

        int ans = dijkstra(a, h, city, G);

        if(ans == 1e9){
            cout << "Help!" << endl;
        }
        else{
            cout << ans << endl;
        }
    }
}


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

int main() {
  int D;
  scanf("%d", &D);

  if (D == 25) {
    printf("Christmas");
  } else if (D == 24) {
    printf("Christmas Eve");
  } else if (D == 23) {
    printf("Christmas Eve Eve");
  } else if (D == 22) {
    printf("Christmas Eve Eve Eve");
  } else {
    // nothing to do
  }
  return 0;
}


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

using namespace std;

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << "Alice" << endl;
    }
    else cout << "Borys"<< endl;
}

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

int N;
string S;
vector<int> seg;

vector<vector<int> > cc;
int dp(int p, int t) {
    if(p >= (int)seg.size() - 1) return 0;
    int &ret = cc[p][t];
    if(ret != -1) return ret;

    ret = 0;

    ret = max(ret, dp(p + 1, 1));
    if(t == 0) {
        return ret;
    }
    if(t == 1) {
        ret = max(ret, seg[p] + dp(p + 1, seg[p + 1] == 1? 0 : 3));
        ret = max(ret, seg[p + 1] + dp(p + 1, 0));
        if(seg[p + 1] > 1) {
            ret = max(ret, seg[p + 1] - 1 + dp(p + 1, 2));
        }
    }
    if(t == 2) {
        ret = max(ret, 1 + dp(p + 1, seg[p + 1] == 1? 0 : 3));
        ret = max(ret, seg[p + 1] + dp(p + 1, 0));
        if(seg[p + 1] > 1) {
            ret = max(ret, seg[p + 1] - 1 + dp(p + 1, 2));
        }
    }
    if(t == 3) {
        ret = max(ret, seg[p] - 1 + dp(p + 1, seg[p + 1] == 1? 0 : 3));
        ret = max(ret, seg[p + 1] + dp(p + 1, 0));
        if(seg[p + 1] > 1) {
            ret = max(ret, seg[p + 1] - 1 + dp(p + 1, 2));
        }
    }

    return ret;
}

int solve(int l, int r) {
    seg.clear();

    int cnt = 0;
    for(int i = l; i <= r; i++) {
        if(S[i] == '0') {
            seg.push_back(cnt);
            cnt = 0;
        }
        else cnt++;
    }
    seg.push_back(cnt);

    cc = vector<vector<int> >(seg.size(), vector<int>(4, -1));
    return dp(0, 1);
}

bool chk(int i) {
    if(i < N - 2) return S[i + 1] == '0' && S[i + 2] == '0';
    if(i < N - 1) return S[i + 1] == '0';
    return true;
}

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

    int s = -1;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(s == -1 && S[i] == '1') s = i;
        if(S[i] == '1' && chk(i)) {
            ans += solve(s, i);
            s = -1;
        }
    }

    cout << ans;
}


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

int main(){
    long long int n,ans=1;
    cin>>n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]>1000000000&&ans>=10000000000){
            cout<<-1<<endl;
            return 0;
        }
        else if(a[i]>=1000000000&&ans>1000000000){
            cout<<-1<<endl;
            return 0;
        }
        if(a[i]*ans>1000000000000000000){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    if(ans>1000000000000000000){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

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

int n;
long long ans;
int a[5];
string m = "MARCH";

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		for(int j=0; j<5; ++j)
			if(m[j] == s[0])
				++a[j];
	}
	for(int i=0; i<3; ++i)
		for(int j=i+1; j<4; ++j)
			for(int k=j+1; k<5; ++k)
				ans += (long long)a[i] * a[j] * a[k];
	cout << ans << "\n";
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  int n,m; cin >> n >> m;
  set<int> d;
  for(int i = 1; i*i <= m; ++i){
    if(m % i == 0){
      d.insert(i);
      d.insert(m/i);
    }
  }
  auto it = d.lower_bound(n);
  cout << m/(*it) << endl;
}



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

public class Main {

	void solve() {
		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
			if (i > 0) {
				a[i] += a[i - 1];
			}
		}
		long best = Long.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			long s1 = a[i], s2 = a[n - 1] - s1;
			best = Math.min(best, Math.abs(s1 - s2));
		}
		out.println(best);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 47384
#include <iostream>
using namespace std;
int H, W, h, w, t, ans, a[501][501];
int main()
{
    cin >> H >> W >> h >> w;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            a[i][j] = 4000;
        }
    }
    t = - h * w * 4000 + 3999;
    for (int i = 0; i <= H; i += h) {
        for (int j = 0; j <= W; j += w) {
            a[i][j] = t;
        }
    }
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            ans += a[i][j];
        }
    }
    if (ans < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j) {
                cout << a[i][j] << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
    //入力
	string s;
    cin >> s;
	int n = s.size();

	long long ans = 0;

    //数字があるたびに現在の値を 10 倍して今書いてある数字だけ足す
	for (int bit = 0; bit < (1 << (n-1)); bit++){
		long long tmp = 0;
		for (int i = 0; i < n; i++){
			tmp *= 10;
            //‘+(’ が出てきたら現在の値が ‘+(’ の直前の整数に等しいので、それを答えに足す
            tmp += s[i] - '0';
			if ((bit & (1 << i)) || i == n - 1){
                //最後は ‘+(’ が登場せずに数式が終わるので、そこは別に足す
				ans += tmp;
                tmp = 0;
			}
		}
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
	int a,one=0,two=0,three=0;
	for (int i=0;i<10;i++){
		cin>>a;
		if (a>three) three=a;
		if (three>two) swap(two,three);
		if (two>one) swap(one,two);
	}
		cout<<one<<endl<<two<<endl<<three<<endl;
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
   ll n;cin >>n;
   ll now=0;
   ll ans=0;
   ll key;
    for (int i = 0; i < n; ++i) {
        ll h;cin >>h;
        if(i==0)key=h;
        else if(h<=key){
            now++;
            key=h;
        }
        else {
            key=h;
            ans=max(ans,now);
            now=0;
        }
    }
    ans=max(ans,now);
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i=0;i<n;i++){
        int h = 0;
        cin >> h;
        if(h >= k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> f(30);
bool kyotu(int a,int b){
  int check =0;
  for(int i=a;i<b-1;i++){
    if(f[i-1]==f[i]) check++;
  }
  if(check == b-a-1) return true;
  return false;
}
bool cubecheck(){
  if(kyotu(1,9)&&kyotu(10,12)&&kyotu(13,15)&&kyotu(16,18)&&kyotu(19,21)&&kyotu(22,30)){
    return true;
  }else{
    return false;
  }
}
void fr(){
  swap(f[13-1],f[18-1]);
  swap(f[9-1],f[24-1]);
  swap(f[7-1],f[22-1]);
  swap(f[8-1],f[23-1]);
  swap(f[10-1],f[12-1]);
}
void ri(){
  swap(f[13-1],f[15-1]);
  swap(f[3-1],f[22-1]);
  swap(f[6-1],f[25-1]);
  swap(f[9-1],f[28-1]);
  swap(f[12-1],f[19-1]);
}

void le(){
  swap(f[1-1],f[24-1]);
  swap(f[4-1],f[27-1]);
  swap(f[7-1],f[30-1]);
  swap(f[10-1],f[21-1]);
  swap(f[16-1],f[18-1]);
}

void ba(){
  swap(f[1-1],f[28-1]);
  swap(f[2-1],f[29-1]);
  swap(f[3-1],f[30-1]);
  swap(f[15-1],f[16-1]);
  swap(f[19-1],f[21-1]);
}
int main(){
  int n;
  cin >> n;
  int q_size;
  for(int j=0;j<n;j++){
   queue< vector<int> > q;
   for(int i=0;i<30;i++){
     cin >>f[i];
   }
   q.push(f);

   for(int l=0;l<8;l++){
     q_size=q.size();

     for(int k=0;k<q_size;k++){
       for(int i=0;i<30;i++){
         f[i]=q.front()[i];
       }
       if(cubecheck()){
         cout << l <<endl;
         break;
       }
       fr();
       q.push(f);
       fr();
       ri();
       q.push(f);
       ri();
       le();
       q.push(f);
       le();
       ba();
       q.push(f);
       ba();
       q.pop();
    }
    if(cubecheck()){
      break;
    }
   }
   if(cubecheck()==0){
     cout << 8 <<endl;
   }
 }
 return 0;
}

Measured memory_bytes: 12664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define INF 0x3F3F3F3F

int a[55],b[55],c[55],d[55];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",a+i,b+i);
	for(int i=1;i<=m;i++)
		scanf("%d%d",c+i,d+i);
	for(int i=1;i<=n;i++)
	{
		int ans=INF,ii=1;
		for(int j=1;j<=m;j++)
		{
			int temp=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(temp<ans)
			{
				ans=temp;
				ii=j;
			}
		}
		printf("%d\n",ii);
	}
	return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
    if x < y:
        t = x
        x = y
        y = t
    while x % y != 0:
        t = x
        x = y
        y = t % x
    return y
N = int(input())
T = [int(input()) for i in range(N)]
LCM = T[0]
for i in range(N-1): 
    g = gcd(LCM, T[i+1])
    LCM = (LCM*T[i+1])//g
print(LCM)

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

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

    //ノード数を決定する
    int N = 0;
    while((1<<N) <= L) N++;
    
    vector<tuple<int, int, int>> ans;
    
    //まずは2^(N-2)までのパスを作る
    for (int i = 0; i < N-1; i++){
        ans.push_back(make_tuple(i+1, i+2, 0));
        ans.push_back(make_tuple(i+1, i+2, (1<<i)));
    }

    // 足りない分を追加する    
    int curMax = (1<<(N-1))-1;

    while(curMax < L-1){
        for(int j = N-2; j>=0; j--){
            if((L- 1 - curMax) >= (1<<j)){
                ans.push_back(make_tuple(j+1, N, curMax+1));
                curMax += (1<<j);
                break;
            }
        }
    }

  cout << N << " " << ans.size() << endl;

  for(int i = 0; i < ans.size(); i++){
    int a, b, c;
    tie(a, b, c) = ans[i];
    cout << a << " " << b << " " << c << endl; 
  } 

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for(i=1;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,n);
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D);
	PAU;
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>
#include <numeric>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); }
	ul lcm(const ul &a,const ul &b) { return (a/gcd(a,b))*b; } // a/gcd(a,b)*b <=> (a*b)/gcd(a,b)
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		for(ul i = 2;i*i < n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}
	ll rho_method(const ll &n)
	{
		auto f = [&](const ll &xi){ return (xi*xi+1)%n; };
		ll x = 2, y = 2, d = 1;
		while(d == 1)
		{
			x = f(x);
			y = f(f(y));
			d = lamlib::gcd(lamlib::abs(x-y),n);
		}
		return d;
	}
	// 素因数分解(試し割)
	std::vector<ll> prime_factorization_trial(const ll &n)
	{
		ll num = n;
		std::vector<ll> prime;
		for(ll i = 2;i*i <= n;++i)
		{
			while((num%i) == 0)
			{
				prime.emplace_back(i);
				num /= i;
			}
		}
		if(num > 1) prime.emplace_back(num);
		return prime;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	int x,n;
	std::cin >> x >> n;

	std::vector<bool> p(100,false);
	for(int i = 0;i < n;++i)
	{
		int tmp;
		std::cin >> tmp;
		p[tmp] = true;
	}

	int diff = std::abs(9999-x);
	int ans = 9999;
	for(int i = 0;i <= 101;++i)
	{
		int tmp = std::abs(i-x);
		if(tmp < diff && !p[i])
		{
			diff = tmp;
			ans = i;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3624
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
s = input()
t = input()

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
d = {c:i for i,c in enumerate(l)}

def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがiより→で最初に現れる位置n[i][c]
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if target is None:
        target = [chr(v) for v in range(ord("a"), ord("z")+1)]
    d = {c:None for c in target}
    nx = [[None]*len(target) for _ in range(len(s))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[0][j]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[-1][j]
    return nx
nx = snx(s, loop=True)
c = -1
ans = 0
for i in range(len(t)):
    nc = nx[(c+1)%len(nx)][d[t[i]]]
    if nc is None:
        ans = -1
        break
    elif nc>c:
        ans += nc-c
    else:
        ans += nc+len(s)-c
    c = nc
print(ans)

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

const int maxn = 2e5;

int n;
int dig[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	int cnt=0;
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	while(n){
	//	cout<<n%(-2)<<endl;
		if(n%(-2)==-1){
			dig[++cnt] = 1;
			n-=2; 
		}
		else{
			dig[++cnt] = (n%(-2));
		}
		n/=(-2);
	//	cout<<"n="<<n<<endl;
	}
	for(int i=cnt; i>=1; i--){
		cout<<dig[i];
	}
}

Measured memory_bytes: 256
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=1e2;
int v[N+10];
int main(){
	int n=read(),Max=-inf,Min=inf;
	for (int i=1;i<=n;i++){
		int x=read();
		Max=max(Max,x);
		Min=min(Min,x);
		v[x]++;
	}
	if (Min!=(Max+1)/2){
		printf("Impossible\n");
		return 0;
	}
	if (v[Min]!=(Max&1)+1){
		printf("Impossible\n");
		return 0;
	}
	for (int i=Min+1;i<=Max;i++){
		if (v[i]<2){
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	return 0;
}

Measured memory_bytes: 256