akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

const llong inf = 1e16;
int n, m;
llong A[5001];
int B[5001][201];
vector<pll> st[201];

llong seg[1 << 14];
llong add[1 << 14];

void lazy(int i) {
    seg[i << 1 | 0] += add[i];
    add[i << 1 | 0] += add[i];
    seg[i << 1 | 1] += add[i];
    add[i << 1 | 1] += add[i];
    add[i] = 0;
}

void update(int i, int s, int e, int x, int y, llong v) {
    if (e < x || y < s) return;
    if (x <= s && e <= y) {
        seg[i] += v;
        add[i] += v;
        return;
    }
    lazy(i);
    int m = (s + e) / 2;
    update(i << 1, s, m, x, y, v);
    update(i << 1 | 1, m + 1, e, x, y, v);
    seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}

llong query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return -inf;
    if (x <= s && e <= y) return seg[i];
    int m = (s + e) / 2;
    return max(query(i << 1, s, m, x, y), 
        query(i << 1 | 1, m + 1, e, x, y)) + add[i];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
        st[i].emplace_back(n + 1, inf);
    for (int i = 2; i <= n; ++i) {
        cin >> A[i];
        A[i] += A[i - 1];
        update(1, 1, n, i, i, -A[i]);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> B[i][j];
        }
    }
    llong ans = 0;
    for (int i = n; i > 0; --i) {
        for (int j = 1; j <= m; ++j) {
            int v = B[i][j];
            while (st[j].back().second <= v) {
                llong pi, pv, ni, nv;
                tie(pi, pv) = st[j].back();
                st[j].pop_back();
                tie(ni, nv) = st[j].back();
                update(1, 1, n, pi, ni - 1, -pv);
            }
            llong idx, val;
            tie(idx, val) = st[j].back();
            st[j].emplace_back(i, v);
            update(1, 1, n, i, idx - 1, v);
        }
        ans = max(ans, query(1, 1, n, i, n) + A[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;


int check(int input)
{
    int temp = sqrt(input) + 1;
    if (input==2)
    {
        return 1;
    }
    
    for (int i = 2; i < temp+1; i++)
    {
        if (input%i==0)
        {
            return 0;
        }
    }
    return 1;
}


int main()
{
    int x;
    cin >> x;
    int flag = 0;
    x--;
    while (flag == 0)
    {
        x++;
        flag=check(x);
    }
    cout << x << endl;
}

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

using namespace std;


int a[100005];

int main(){
    int n;
    while(cin >> n, n){
        long long s = 0;
        for(int i = 0; i < n; ++i){
            cin >> a[i];
            s += a[i];
        }
        int ret = 0;
        for(int i = 0; i < n; ++i){
            if(s >= a[i]*n) ++ret;
        }
        cout << ret << endl;
        
    }
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

bool isg(string s)
{
  if(s.size()%2==1) return false;
  REP(i, s.size()/2) {
    if(s[i]!=s[i+s.size()/2]) return false;
  }
  return true;
}


int main(void)
{
  string s;
  cin >> s;
  for(int i = s.size() - 1; i > 1; i--) {
    s.erase(i-1);
    if(isg(s)) {
      cout << s.size() << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
// Problem : B - Tag
// Contest : AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest 2020
// URL : https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;


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

    long long a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a < b) {
        long long aa = a + t * v;
        long long bb = b + t * w;
        if (aa >= bb) cout << "YES\n";
        else cout << "NO\n";
    } else {
        long long aa = a - t * v;
        long long bb = b - t * w;
        if (aa <= bb) cout << "YES\n";
        else cout << "NO\n";
    }
    
    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    string S;
    bool alphabet[26]={false};
    char ans[26];

    cin >> S;
    rep(i,S.size()){
        alphabet[S[i]-'a']=true;
    }
    int j=0;
    rep(i,26){
        if(!alphabet[i]) {
            ans[j] = 'a' + i;
            j++;
        }
    }
    ans[j]='\0';
    if(ans[0]=='\0'){
        cout << "None" << endl;
    }else{
        cout << ans[0] << endl;
    }

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



Measured memory_bytes: 512
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;


#[allow(dead_code)]
static INF_I64 :i64 = 9223372036854775807;
#[allow(dead_code)]
static INF_I32 : i32 = 2147483647;
#[allow(dead_code)]
static INF_USIZE : usize = 18446744073709551615;



fn main() {

    input! { 
       n: usize,
    }

    let mut a = 0_f64;
    let mut b= 0_f64;
    for i in 1..n+1{
        if (i as i64 % 2 == 0){
            a+=1.0;
        }
        else {
            b+=1.0;
        }

    }

    let mut ans = 0_f64;
    ans = b/n as f64;
    
    
    println!("{}",ans);


}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  if (n>=30) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>



using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll mod = 1000000007;

using namespace std;

int main() {
	const double pi = 3.141592;
	double r;

	cin >> r;
	cout << 2 * pi * r << endl;

 	return 0;
}


Measured memory_bytes: 3296
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map> 
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
#include <set>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define INF_L (LLONG_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
#define int long long


// booooooooooooost
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)


signed main() {

	int H, W;
	int chars[26];
	for (int i = 0; i < 26; ++i) chars[i] = 0;

	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < W; ++j) {
			chars[s[j] - 97]++;
		}
	}

	vector<int> nums(5);
	for (int i = 0; i < 5; ++i) nums[i] = 0;

	if (H % 2 == 0 && W % 2 == 0) {
		nums[4] = H * W / 4;
	}
	else if (H % 2 == 1 && W % 2 == 0) {
		nums[4] = (H - 1) * W / 4;
		nums[2] = W / 2;
	}
	else if (H % 2 == 0 && W % 2 == 1) {
		nums[4] = H * (W - 1) / 4;
		nums[2] = H / 2;
	}
	else {
		nums[4] = (H - 1) * (W - 1) / 4;
		nums[2] = (W + H - 2) / 2;
		nums[1] = 1;
	}

	bool ans = true;
	while (nums[4] != 0) {
		for (int i = 0; i < 26; ++i) {
			if (chars[i] >= 4) {
				chars[i] -= 4;
				--nums[4];
				break;
			}

			if (i == 25) {
				ans = false;
				nums[4] = 0;
			}
		}
	}
	while (nums[2] != 0) {
		for (int i = 0; i < 26; ++i) {
			if (chars[i] >= 2) {
				chars[i] -= 2;
				--nums[2];
				break;
			}

			if (i == 25) {
				ans = false;
				nums[2] = 0;
			}
		}
	}
	while (nums[1] != 0) {
		for (int i = 0; i < 26; ++i) {
			if (chars[i] >= 1) {
				chars[i] -= 1;
				--nums[1];
				break;
			}

			if (i == 25) {
				ans = false;
				nums[1] = 0;
			}
		}
	}

	cout << (ans ? "Yes" : "No") << endl;


	

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
k = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    k[a-1].append(h[b-1])
    k[b-1].append(h[a-1])
a = 0
for i in range(n):
    if k[i] == [] or h[i] > max(k[i]):
        a += 1
print(a)

Measured memory_bytes: 92660
import           Control.Monad

main :: IO ()
main = do
    [_, a, b] <- map read . words <$> getLine
    s         <- getLine
    putStrLn $ solve a b s

solve :: Int -> Int -> String -> String
solve a b []       = ""
solve a b (c : cs) = case c of
    'a' | a + b > 0 -> "Yes\n" ++ solve (a - 1) b cs
        | otherwise -> "No\n" ++ solve a b cs
    'b' | a + b > 0 && b > 0 -> "Yes\n" ++ solve a (b - 1) cs
        | otherwise          -> "No\n" ++ solve a b cs
    'c' -> "No\n" ++ solve a b cs

Measured memory_bytes: 5372
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] line = br.readLine().split(" ");
        int[] nums = new int[n];

        for(int i = 0; i < n; i++){
            nums[i] = Integer.parseInt(line[i]);
        }
        for(int i = 0; i < n; i++){
            System.out.print(nums[i]);
            if(i != n-1){
                System.out.print(" ");
            }
        }
        System.out.print("\n");

        for(int i = 1; i < n; i++){

            int key = nums[i];
            int j = i - 1;

            while(j >= 0 && nums[j] > key){
                nums[j+1] = nums[j];
                j--;
            }
            nums[j+1] = key;
            for(int x = 0; x < n; x++){
                System.out.print(nums[x]);
                if(x != n-1){
                    System.out.print(" ");
                }
            }
            System.out.print("\n");
        }
    }
}

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

int main() {
  long long n;
  scanf("%lld", &n);

  long long s = 0, t = 1;
  int l = 0;
  while (true) {
    l++;
    t *= 26;

    if (s + t >= n) {
      long long x = n - s - 1;
      vector<int> a(l);
      for (int i = 0; i < a.size(); i++) {
        a[i] = x % 26;
        x /= 26;
      }

      for (auto it = a.rbegin(); it != a.rend(); it++) {
        printf("%c", 'a' + *it);
      }
      printf("\n");

      break;
    }

    s += t;
  }

  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define A 110
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	
	cin >> n;
	
	while(n != 0){
		if(n % 10 == 7){
			cout << "Yes" << endl;
			return 0;
		}
		
		n /= 10;
	}
	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a,li[30];
vector<int> vec;

int main(){
	cin >> n; li[0]=true;
	REP(i,0,n){
		cin >> a;
		if(li[a] and li[24-a]){cout << 0 << endl; return 0;}
		else if(li[a] and !li[24-a]) li[24-a]=true;
		else li[a]=true; 
	}
	
	ll ei=0;
	REP(i,0,25) if(li[i] and li[24-i]) ei+=(1<<i);
	REP(i,0,25) if(li[i]) vec.push_back(i);
	sort(vec.begin(), vec.end());
	
	int ma=0;
	REP(i,0,(1<<vec.size())){
		if(ei&i) continue;
		set<int> st;
		vector<int> pos;
		bool f=false;
		int mi=INF;
		
		REP(j,0,vec.size()){
			if((i>>j)&1 and st.count(24-vec[j])){f=true; break;}
			else if((i>>j)&1) st.insert(24-vec[j]),pos.push_back(24-vec[j]);
			else if(st.count(vec[j])){f=true; break;}
			else st.insert(vec[j]),pos.push_back(vec[j]);
		}
		
		if(f) continue;
		sort(pos.begin(), pos.end());
		REP(i,0,pos.size()-1) mi=min(mi,pos[i+1]-pos[i]);
		mi=min(mi, min(abs(pos[pos.size()-1]-pos[0]), abs(24-(pos[pos.size()-1]-pos[0]))));

		ma=max(ma,mi);
	}
		
	cout << ma << endl;
	return 0;
}


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

int main() {

int i,n;

cin >> n;

vector<int> a(n);

for(i=0;i<=n-1;++i){
cin >> a.at(i);
}

for(i=n-1;i>=0;--i){
if(i==0){
cout << a.at(i) ;
}else{
cout << a.at(i) << " ";
}
}
cout << endl;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
  int e;
  while(scanf("%d",&e),e){
    int x,y,z,ans=10000000;
    for(z=100; z>=0; z--){
      if(z*z*z>e) continue;
      
      for(y=0; y*y<=e-z*z*z; y++){
	x = e-y*y-z*z*z;
	ans = min(ans,x+y+z);
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1028
import sys
a, b, m = [int(x) for x in input().split()]
a_s = [int(x) for x in input().split()]
b_s = [int(x) for x in input().split()]
discounts = [[int(x) for x in input().split()] for i in range(m)]
m = min(a_s) + min(b_s)
for (x, y, c) in discounts:
    v = a_s[x - 1] + b_s[y - 1] - c
    m = min(m, v)
print(m)



Measured memory_bytes: 32496
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		if(str.charAt(0) == str.charAt(1) && str.charAt(1) == str.charAt(2)) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 26916
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0;
	long long o = 0, p = 0, q = 0, r = 0, s = 0, t = 0, u = 0, v = 0, w = 0, x = 0, y = 0, z = 0, ans = 1;
	string ss; cin >> ss;
	for (int hh = 0; hh < ss.size(); hh++) {
		if (ss[hh] == 'a') { a++; } if (ss[hh] == 'b') { b++; }
		if (ss[hh] == 'c') { c++; } if (ss[hh] == 'd') { d++; } if (ss[hh] == 'e') { e++; }
		if (ss[hh] == 'f') { f++; } if (ss[hh] == 'g') { g++; } if (ss[hh] == 'h') { h++; }
		if (ss[hh] == 'i') { i++; } if (ss[hh] == 'j') { j++; } if (ss[hh] == 'k') { k++; }
		if (ss[hh] == 'l') { l++; } if (ss[hh] == 'm') { m++; } if (ss[hh] == 'n') { n++; }
		if (ss[hh] == 'o') { o++; } if (ss[hh] == 'p') { p++; } if (ss[hh] == 'q') { q++; }
		if (ss[hh] == 'r') { r++; } if (ss[hh] == 's') { s++; } if (ss[hh] == 't') { t++; }
		if (ss[hh] == 'u') { u++; } if (ss[hh] == 'v') { v++; } if (ss[hh] == 'w') { w++; }
		if (ss[hh] == 'x') { x++; } if (ss[hh] == 'y') { y++; } if (ss[hh] == 'z') { z++; }
	}
	ans = ss.size() * (ss.size() - 1) / 2 + 1;
	ans -= a * (a - 1) / 2; ans -= b * (b - 1) / 2; ans -= c * (c - 1) / 2; ans -= d * (d - 1) / 2;
	ans -= e * (e - 1) / 2; ans -= f * (f - 1) / 2; ans -= g * (g - 1) / 2; ans -= h * (h - 1) / 2;
	ans -= i * (i - 1) / 2; ans -= j * (j - 1) / 2; ans -= k * (k - 1) / 2; ans -= l * (l - 1) / 2;
	ans -= m * (m - 1) / 2; ans -= n * (n - 1) / 2; ans -= o * (o - 1) / 2; ans -= p * (p - 1) / 2;
	ans -= q * (q - 1) / 2; ans -= r * (r - 1) / 2;
	ans -= s * (s - 1) / 2; ans -= t * (t - 1) / 2; ans -= u * (u - 1) / 2; ans -= v * (v - 1) / 2;
	ans -= w * (w - 1) / 2; ans -= x * (x - 1) / 2; ans -= y * (y - 1) / 2; ans -= z * (z - 1) / 2;
	cout << ans << endl;
	cin >> n;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n, k;
  cin >> n >> k;
  bool judge = true;
  ll result = 0;
  ll buf;
  
  vector<ll> a(n);
  for(i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == 1)
      buf = i + 1;
  }
   
  
  
  cout << (n - 1 + k - 2) / (k - 1) << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	private static final Scanner S=new Scanner(System.in);
	private static final PrintStream O=System.out;
	
	public static void main(String[] args) {
		String s=S.nextLine().replace("apple", "p0p");
		s=s.replace("peach", "apple");
		s=s.replace("p0p", "peach");
		O.println(s);
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <set>
#include <stdio.h>
using namespace std;

int main()
{
    multiset<int> S;
    int query;
    int command, num, L, R;
    multiset<int>::iterator itrL, itrR;

    scanf("%d", &query);
    for (int i = 0; i < query; i++)
    {
        scanf("%d", &command);
        switch (command) {
        case 0:
            scanf("%d", &num);
            S.insert(num);
            printf("%d\n", S.size());
            break;
        case 1:
            scanf("%d", &num);
            printf("%d\n", S.count(num));
            break;
        case 2:
            scanf("%d", &num);
            S.erase(num);
            break;
        case 3:
            scanf("%d %d", &L, &R);
            itrL = S.lower_bound(L);
            itrR = S.upper_bound(R);
            while (itrL != itrR)
            {
                printf("%d\n", *itrL++);
            }
            break;
        default:
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 12472
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, 0, n)
        cin >> v[i];
    int max = *max_element(v.begin(), v.end());
    int min = *min_element(v.begin(), v.end());
    cout << max - min;
    return 0;
}

Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X = getlist()
	for i in range(5):
		if X[i] != i + 1:
			print(i + 1)
			return




if __name__ == '__main__':
	main()

Measured memory_bytes: 64708
import java.io.IOException;
import java.util.Scanner;


public class Main{
	public static void main(String[] args) throws IOException{
		
		int n;
		int A, B;
		int bufA, bufB;
		Scanner scanner = new Scanner(System.in);
		while (true) {		
			n = scanner.nextInt();
			bufA = 0;
			bufB = 0;
			if (n > 0) {
				for (int i = 0; i < n; i++) {
						A = scanner.nextInt();
						B = scanner.nextInt();
						if (A > B) {
							bufA = A + B + bufA;
						} else if (A < B) {
							bufB = A + B + bufB;
						} else {
							bufA = A + bufA;
							bufB = B + bufB;
						}
				}
				System.out.println(bufA + " " + bufB);
			} else {
				break;
			}
		}
	}
}

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

#define int long long
#define f(i,a,b) for(int i=a;i<b;i++)

using namespace std;
int dp[200000][101]={0};
signed main(){
    int s,n;
    cin>>n>>s;
    int arr[n],val[n];
    f(i,0,n){
        cin>>arr[i]>>val[i];
    }
    int mn=INT_MAX,index=0;
    f(i,0,n){
        mn=min(mn,arr[i]);
        if(mn==0)
            index=i;
    }
    
    dp[0][0] = 0;

    f(i,1,s+1){
        f(j,0,n){
            if(i-arr[j]>=0){
                dp[i][j] = max(dp[i][j],dp[i-arr[j]][j-1]+val[j]);
            }
            dp[i][j] = max(dp[i][j],dp[i][j-1]);
        }
    }
    int ans=0;
    f(i,0,n+1){
        ans = max(ans,dp[s][i]);
    }
    cout<<ans;
}






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

typedef long long ll;

typedef pair<int, int> p;

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

    int X, A, B;
    cin >> X >> A >> B;

    if(A >= B) {
        cout << "delicious" << endl;
    } else if(X + A >= B) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
from bisect import bisect
N = int(input())
xs = list(map(int,input().split()))
L = int(input())
Q = int(input())
qs = [tuple(map(lambda x:int(x)-1, input().split())) for i in range(Q)]

K = len(bin(N)) - 1
dp = [[None]*N for i in range(K)]
for i,x in enumerate(xs):
    dp[0][i] = bisect(xs, x+L) - 1
for k in range(K-1):
    for i in range(N):
        dp[k+1][i] = dp[k][dp[k][i]]

def enough(fr,to,n):
    now = fr
    bn = bin(n)
    ln = len(bn)-2
    for i,c in enumerate(bn[2:]):
        if c=='0': continue
        now = dp[ln-1-i][now]
        if now >= to:
            return True
    return False

ans = []
for a,b in qs:
    if a>b: a,b = b,a
    ok = N
    ng = 0
    while ok-ng > 1:
        m = (ok+ng)//2
        if enough(a,b,m):
            ok = m
        else:
            ng = m
    ans.append(ok)

print(*ans,sep='\n')

Measured memory_bytes: 109464
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int data = sc.nextInt();

		for(int i=0; i<data; i++){
			int x = 0, y = 0;
			int[] treasure = new int[3];

			while(true){
				int dx = sc.nextInt();
				int dy = sc.nextInt();
				if(dx==0&&dy==0) break;
				x += dx;
				y += dy;
				if(x*x+y*y>treasure[0]){
					treasure[0] = x*x+y*y;
					treasure[1] = x;
					treasure[2] = y;
				}else if(x*x+y*y==treasure[0]&&x>treasure[1]){
					treasure[1] = x;
					treasure[2] = y;
				}
			}
			System.out.println(treasure[1] + " " + treasure[2]);
		}
	}
}

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

const int mod = 1000000007;

char s[5010];
long long f[5010][5010];
long long inv[5010];

long long power(long long a, long long b){
	if (b == 0) return 1;
	long long t = power(a, b / 2);
	t = t * t % mod;
	return b & 1 ? t * a % mod : t;
}

int main(){
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	int len = strlen(s);
	inv[1] = 1, inv[2] = (mod - mod / 2) * inv[mod % 2] % mod;
	f[0][0] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= n; j++){
			f[i][j] = (f[i][j] + 2 * f[i - 1][j - 1] % mod) % mod;
			f[i][j] = (f[i][j] + f[i - 1][j + 1]) % mod;
			if (j == 0) f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
		}
	}
	printf("%lld\n", f[n][len] * power(inv[2], len) % mod);
	return 0;
}


Measured memory_bytes: 195968
N, M = map(int, input().split())
a = list(map(int, input().split()))
import heapq
class Heapq:
    # 最大値を取り出す際は desc=True に設定
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
    
hp = Heapq(a, desc=True)
for i in range(M):
    max_ = hp.pop() // 2
    hp.push(max_)
    
ans = 0
for i in range(N):
    #print(hp.top())
    ans += hp.pop()
print(ans)

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

int main(void){
    int n,k;
    cin >> n >> k;
    
    long double ans = 0;
    for(int i = 1;i <= n;i++){
        int alina = i;
        long double cnt = 1;
        while( 1 ){
            if(alina >= k)break;
            alina *= 2;
            cnt /= 2;
        }
        ans += cnt;
    }
    cout << setprecision(20) << ans / n << endl;
}

Measured memory_bytes: 3764
#include <iostream>
#include <iomanip> 
using namespace std ;
int main () {
	double  r, a, c, p ;
	cin >> r ;
	p = 3.141592653589793 ;
	a = r * r * p ;
	c = 2 * r * p ;
	cout << fixed << setprecision(10) ;
	cout << a << " " << c << endl ;
}


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

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

  vector<int> A(N);
  for ( int i = 0; i < N; i++ ) cin >> A.at(i);

  int x = 1;
  int z = 0;
  while (1) {
  	int a = A.at(x-1);
  	z++;
  	if ( a == x ) {
  	  z = -1;
  	  break;
  	} else if ( a == 2 ) {
  	  break;
  	}

  	A.at(x-1) = x;
  	x = a;
  }

  cout << z << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10;
const ll mod =   1e9+7;
int n,m;
vector<int> ans(N,0);
vector<int> g[N];
bool b[N];

int main()
{  fast
cin>>n>>m;
for(int i=0;i<m;i++)
{
	int x,y;
	cin>>x>>y;
	g[x].emplace_back(y);g[y].emplace_back(x);
}
b[1]=true;
queue<int> q;
q.push(1);
while(!q.empty())
{
	int x=q.front();
	q.pop();
	for(auto it : g[x])
	if(!ans[it]){
	 q.push(it);
	ans[it]=x;}
}
cout<<"Yes\n";
for(int i=2;i<=n;i++)
cout<<ans[i]<<endl;





}

Measured memory_bytes: 12964
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    if (N >= 2) {
        if (N % 2 == 0) {
            cout << N << endl;
        } else {
            cout << 2 * N << endl;
        }
    } else {
        cout << 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  
  	int n;
  	cin>>n;
  	vector<int> f(n+1);
  	vector<int> sqrt(10*n+1,-1);
  	for(int i=0;i*i<=10*n;i++) {
  		sqrt[i*i] = i;
  	}
  	vector<vector<vector<int>>> ans(n+1);
  	for(int x=1;x*x<=n;x++) {
  		for(int y=1;y*y<=n;y++) {
  			for(int N=1;N<=n;N++) {
  				int m = N - (x*x + y*y + x*y);
  				int d = (x+y)*(x+y) + 4*m;
  				if(d >= 0 && sqrt[d] != -1) {
  					int z = sqrt[d] - (x + y);
  					if(z >0 && z%2==0) {
  						f[N]++;
  						ans[N].push_back({x,y,z/2});
  					}
  				}
  			}
  		}
  	}
  	for(int i=1;i<=n;i++) {
  		/*cout<<"Level = "<<i<<":\n";
  		for(int k=0;k<ans[i].size();k++) {
  			for(auto it:ans[i][k]) {
  				cout<<it<<" ";
  			}
  			cout<<"\n";
  		}*/
  		cout<<f[i]<<"\n";
  	}
}


Measured memory_bytes: 20272
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int par[100010];
int rnk[100010];

// 初期化
void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

// 親探し
int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

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

// 同じ木にあるか
bool same(int x, int y) {
    return find(x) == find(y);
}

int main(void){
    int n, q;
    cin >> n >> q;
    
    init(n);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) cout << same(x, y) << endl;
        else unite(x, y);
    }
    
}



Measured memory_bytes: 3184
<?php
fscanf(STDIN,"%d %d",$n,$l);

$min=1000000;
$t_sum=0;
for($i=1;$i<=$n;$i++){
	if(abs($l+($i-1))<$min){
		$min=abs($l+($i-1));
		$min_atai=$l+($i-1);
	}
	$t_sum += $l+($i-1);
}

echo $t_sum-$min_atai;

?>

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

int main(){
  int n,m,p,x;
  cin >> n;
  vector<int> t(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> t[i];
    sum+=t[i];
  }
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> p >> x;
    cout << sum-t[p-1]+x << endl;
  }
}


Measured memory_bytes: 256
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, input().split())
    count = Counter()
    for _ in range(H):
        count += Counter(input())

    four = (H // 2) * (W // 2)
    two = (H // 2) * (W % 2) + (W // 2) * (H % 2)
    one = (H % 2) * (W % 2)

    for value in count.values():
        while value >= 4 and four > 0:
            value -= 4
            four -= 1
        while value >= 2 and two > 0:
            value -= 2
            two -= 1
        while value >= 1 and one > 0:
            value -= 1
            one -= 1

    if four == two == one == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9480
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	
	int n,d,a;
	cin>>n>>d>>a;

	vector<pair<int, int>>xh(n);

	for(i=0;i<n;i++)
	{
		cin>>xh[i].ff>>xh[i].ss;
	}

	sort(all(xh));

	vector<int>needed(n);

	for(i=0;i<n;i++)
	{
		needed[i]=ceil(xh[i].ss/(ld)a);
	}

	d(needed);

	vector<int>last(n,0);
	int ans=0;

	j=1;

	for(i=0;i<n;i++)
	{
		while(j<n&&xh[j].ff-xh[i].ff<=2*d)
		{
			j++;
		}
		int cnt=max(0LL,needed[i]-last[i]);
		d(i,j,cnt,last);
		ans+=cnt;
		last[i]+=cnt;

		if(i==n-1)
		{
			break;
		}

		last[j]-=cnt;

		last[i+1]+=last[i];

	}
	cout<<ans<<endl;

}

Measured memory_bytes: 9540
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <bitset>
using namespace std;

int pownum;

int main(){

    int N,K;

    cin >> N>> K;

    uint64_t DpN[200001] = {};
    uint64_t sumDpN[200001] ={};

    int Li[10]={};
    int Ri[10]={};

    for(int i=0;i<K;++i){
        cin >> Li[i] >> Ri[i];
    }

    DpN[0]=0;
    sumDpN[0]=0;
    DpN[1]=1;
    sumDpN[1]=1;

    for(int i=2;i<=N;++i){
        for(int j=0;j<K;++j){
            int temphigh = i-Li[j];
            int templow  = i-Ri[j]-1;

            if(templow < 0){
                templow =0;
            }
            if(temphigh < 0){
                temphigh =0;
            }            
            DpN[i] += sumDpN[temphigh] -sumDpN[templow];
        }
        DpN[i] = DpN[i] % 998244353;
        sumDpN[i] = sumDpN[i-1] + DpN[i]; 

    }

    cout<< DpN[N] << endl;

}



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

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> arr(n);
    priority_queue<ll> pq;

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        pq.push(arr[i]);
    }

    while (m) {
        ll top = pq.top();
        pq.pop();

        top = top / 2;
        m--;

        pq.push(top);
    }

    ll ans = 0;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <math.h>

using namespace std;

int main(void) {

	int x, a, b;
	char ans;

	cin >> x >> a >> b;

	ans = abs(x - a) < abs(x - b) ? 'A' : 'B';

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
n, m, Q = map(int, input().split())

class Cumulative_Sum_2D:
    def __init__(self, a):
        lai = len(a)
        laj = len(a[0])
        self.s = [[0] * (laj + 1) for _ in range(lai + 1)]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] = self.s[i+1][j] + a[i][j]
        for i in range(lai):
            for j in range(laj):
                self.s[i+1][j+1] += self.s[i][j+1]
    def sum(self, li, lj, ri, rj):
        s = self.s
        return s[ri][rj] - s[li][rj] - s[ri][lj] + s[li][lj]

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

cs = Cumulative_Sum_2D(a)

for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    print(cs.sum(p,p, q+1,q+1))


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

int f(int n, int k){
	if(n == 1) return 0;
	else return (f(n - 1, k) + k) % n;
}
int main(){
	int N, K, M;
	while(cin >> N >> K >> M, N){
		cout << ((f(N - 1, K) + M) % N + 1) << endl;
	}
}

Measured memory_bytes: 3316
program abc
	implicit none
	integer(8) :: k,n
    integer :: l,m,x,y
	integer :: an(200000)=0 

	read(*,*) k,n
	read(*,*) (an(m),m=1,n)
 
	x = 0

	do m = 1, n
    	if(m /= n) then
	    	l = an(m+1) - an(m)
        else
        	l = k - an(m) + an(1)
        endif
        
		if(l >= x) then
    		x = l
		endif
	enddo
	
	y = k - x
 
	write(*,*) y

end program abc

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i, m) cin >> s.at(i) >> c.at(i);

    int begin, end;
    if (n == 1)
    {
        begin = 0;
        end = 9;
    }
    else if (n == 2)
    {
        begin = 10;
        end = 99;
    }
    else if (n == 3)
    {
        begin = 100;
        end = 999;
    }

    int answer = -1;
    for (int i = begin; i <= end; i++)
    {
        string number = to_string(i);
        bool is_ok = true;
        for (int j = 0; j < m; j++)
        {
            if (number.at(s.at(j) - 1) != c.at(j))
            {
                is_ok = false;
                break;
            }
        }
        if (is_ok == true)
        {
            answer = i;
            break;
        }
    }

    cout << answer << endl;
}

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

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=a*c;
    if(ans<a*d) ans=a*d;
    if(ans<b*c) ans=b*c;
    if(ans<b*d) ans=b*d;
    cout<<ans<<endl;
}

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

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

    if(M & 1) {
        for(int i=1; i<=(M/2); ++i) {
            cout << i << ' ' << M + 1 - i << '\n';
        }
        for(int i=1; i<=(M/2)+1; ++i) {
            cout << M + i << ' ' << 2 * M + 2 - i << '\n';
        }
    } else {
        for(int i=1; i<=(M/2); ++i) {
            cout << i << ' ' << M + 2 - i << '\n';
        }
        for(int i=1; i<=(M/2); ++i) {
            cout << M + 1 + i << ' ' << 2 * M + 2 - i << '\n';
        }
    }
}

Measured memory_bytes: 3616
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

int N;
int check(int x) {
	cout << x << endl << flush; 
	string s;
	cin >> s; 
	if(s == "Vacant") return 0;
	else if(s == "Male") return 1;
	else return -1;
}


int main(){
	//ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> N;
	string s;
	int l = 0,r=N;
	int m = (l+r)/2;
	int lx = check(l);
	int rx = lx;
	while(l + 1 < r) {
		m = (l+r)/2;
		int mx = check(m);
		if(mx == lx) {
			if( (m-l+1)%2 ) {
				l=m;
				lx =mx;
			} else {
				r=m;
				rx = mx;
			}
		} else {
			if( (m-l+1)%2 ) {
				r = m;
				rx = mx;
			} else {
				l=m;
				lx = mx;
			}
		}
	}
	check(r);
}




Measured memory_bytes: 852
//Name: Chain Disappearance Puzzle
//Level: 2
//Category: シミュレーション
//Note:

/**
 * 素直にシミュレーションすればよい。
 * 消える石にマークする処理と、消えたところに石を詰める処理は別々に行わないといけないことに注意する。
 *
 * オーダーは O(H^2)。
 */
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void mark(vector<vector<int>> &field, int r, int c, int cnt) {
    for(int cc = c-cnt+1; cc <= c; ++cc) {
        field[r][cc] = 0;
    }
}

int sim(vector<vector<int>> &field) {
    const int H = field.size();
    int score = 0;
    for(int r = 0; r < H; ++r) {
        int cnt = 0;
        int prev = -1;
        for(int c = 0; c < 5; ++c) {
            if(field[r][c] == prev) {
                ++cnt;
            } else {
                if(cnt >= 3 && prev != 0) {
                    score += cnt * prev;
                    mark(field, r, c-1, cnt);
                }
                cnt = 1;
            }
            prev = field[r][c];
        }
        if(cnt >= 3 && prev != 0) {
            score += cnt * prev;
            mark(field, r, 4, cnt);
        }
    }
    if(score > 0) {
        for(int r = H-1; r >= 0; --r) {
            for(int c = 0; c < 5; ++c) {
                if(field[r][c] == 0) {
                    for(int rr = r-1; rr >= 0; --rr) {
                        if(field[rr][c] != 0) {
                            field[r][c] = field[rr][c];
                            field[rr][c] = 0;
                            break;
                        }
                    }
                }
            }
        }
    }
    return score;
}

bool solve() {
    int H;
    if(!(cin >> H)) return false;
    if(!H) return false;

    vector<vector<int>> field(H);
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < 5; ++j) {
            int v;
            cin >> v;
            field[i].push_back(v);
        }
    }

    int ans = 0;
    while(true) {
        const int score = sim(field);
        if(score == 0) break;
        ans += score;
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

typedef long long int LLI;

int N;
int ans;
LLI sum;
int cnt[32];
LLI as[114514];

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    scanf("%lld", &as[i]);
    sum ^= as[i];
    for (int j=0; j<32; j++) {
      if (as[i] >> j & 1) {
        cnt[j]++;
        break;
      }
    }
  }

  for (int i=31; i>=0; i--) {
    if (sum >> i & 1) {
      LLI t = 1LL << i;
      if (cnt[i] <= 0) {
        puts("-1");
        return 0;
      }

      sum ^= t;
      --t;
      sum ^= t;
      ans++;
    }
  }

  if (sum == 0) {
    printf("%d\n", ans);
  } else puts("-1");
}


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

n, m = [int(x) for x in input().split()]
ans = 0

#約数の列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

g = make_divisors(m)

for i in g:
    if m // i >= n:
        ans = i
print(ans)


Measured memory_bytes: 38640
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int a,b;cin>>a>>b;
    if(a<b)cout<<"0\n";
    else cout<<"10\n";
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    //#endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    //#ifndef ONLINE_JUDGE
    //cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    //#endif
    return 0;
}

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

struct UnionFind{

    vector<int> par;
    vector<int> sizes;

    UnionFind(int n):par(n),sizes(n,1){
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int find(int x) { //xの根を得る
        if (x == par[x]) return x;
        return par[x] = find(par[x]); //根を張り替えながら再帰的に根ノードを探す
    }

    void unite(int x, int y) { //xとyの集合を併合
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

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

    int size(int x) {
        return sizes[find(x)];
    }
};

int main(){
    int N,M; cin >> N >> M;
    UnionFind uf(N);
    int ans=0;
    bool used[N];
    int x[M],y[M];
    for(int i=0;i<M;i++){
        int z; cin >> x[i] >> y[i] >> z;
        x[i]--;y[i]--;
        uf.unite(x[i],y[i]);
    }
    set<int> se;
    for(int i=0;i<N;i++){
        se.insert(uf.find(i));
    }
    cout << se.size() << endl;
}

Measured memory_bytes: 6400
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for j in range(h):
        for i in range(w):
            if (j+i) % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()
                


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

class segtree{
	public:
	int n;
	vector<int> data;
	segtree(int n_){
		n=1;
		while(n<n_)	n*=2;
		data=vector<int>(2*n-1,INT_MAX);
	}
	void update(int k,int a){
		k+=n-1;
		data[k]=a;
		while(k){
			k=(k-1)/2;
			data[k]=min(data[2*k+1],data[2*k+2]);
		}
	}
	int query(int l,int r,int a,int b,int k){
		if(r<=a||b<=l)	return INT_MAX;
		if(a<=l&&r<=b)	return data[k];
		int mid=(l+r)/2;
		return min(query(l,mid,a,b,2*k+1),query(mid,r,a,b,2*k+2));
	}
};

int main(){
	int n,q;	cin>>n>>q;
	segtree seg(n);
	while(q--){
		int c,x,y;	cin>>c>>x>>y;
		if(c==0)	seg.update(x,y);
		else if(c==1)	cout<<seg.query(0,seg.n,x,y+1,0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3116