akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

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

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

ll ar[200500];
ll get_st(ll a) {
    ll p = 1;
    while (p <= a) {
        p *= 2;
    }
    return p;
}
map<ll, int> cnt;

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    srand(time(NULL));
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    int n;
    cin >> n;
    forn(i, n)
        cin >> ar[i];
    sort(ar, ar + n);
    reverse(ar, ar + n);
    int ans = 0;
    forn(i, n) {
        ll a = ar[i];
        ll p = 1LL << 30;
        int flag = 0;
        while (p > a) {
            if (cnt[p - a]) {
                --cnt[p - a];
                flag = 1;
                break;
            }
            p >>= 1;
        }
        if (flag) {
            ans++;
        } else
            cnt[a]++;
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 40192
import math

n = input()
As = list(map(int, input().split()))
gcd = As[0]
for a in As[1:]:
    tmp = gcd
    gcd = math.gcd(tmp, a)

if gcd > 1:
    print("not coprime")
    exit()

era = [0] * (10**6 + 1)
for a in As:
    era[a] += 1
for d in range(2, 10**6+1):
    data = [i for i in range(d,10**6+1,d)]
    cnt = 0
    for i in data:
        cnt += era[i] 
    if cnt > 1:
        print("setwise coprime")
        exit()
print("pairwise coprime")

    

Measured memory_bytes: 205640
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n,x;
  long long int a[100];
  scanf("%d%d",&n,&x);
  for(int i = 0; i<n;i++){
    scanf("%lld",&a[i]);
  }
  sort(a,a+n);

  int ans = 0;
  for(int i=0;i<n;i++){
    x-=a[i];
    ans++;
    if(x<=0)break;
    
  }
  if(x!=0)ans--;
  if(ans<0)ans=0;
  printf("%d\n",ans);


  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, m;
    cin >> n >> m;
    int x = 1;
    rep(i, m) {
        x *= 2;
    }
    x *= (n-m)*100+m*1900;

    cout << x << endl;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N = I()
T, A = LI()
H = LI()

result = 10**18
result_idx = 0
for idx, h in enumerate(H):
    height = T - h * 0.006
    if abs(A - height) < result:
        result = abs(A - height)
        result_idx = idx + 1

print(result_idx)


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

int main() 
{
	string hoge;
	cin >> hoge;
	if (hoge == "Cloudy") {
    	cout << "Rainy" << endl;
    } else if (hoge == "Rainy") {
    	cout << "Sunny" << endl;
    } else if (hoge == "Sunny") {
    	cout << "Cloudy" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    string s, t;
    int ans = 1<<29;
    cin >> s >> t;
    vector<char> a(s.length()), b(t.length());
    rep(i, s.length()){
        a.at(i) = (char)s.at(i);
    }
    rep(i, t.length()){
        b.at(i) = (char)t.at(i);
    }
    rep(i, s.length()){
        int count = 0;
        if(i + t.length() > s.length()) break;
        rep(j,t.length()){
            if(a.at(i + j) != t.at(j)) {
                count ++;
            }
        }
        chmin(ans, count);
    }
    cout << ans << endl;
}

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


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

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }
    
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        l: i32,
    }
    let apples = (0..n).map(|i| l + i as i32).collect::<Vec<_>>();
    let mut min = 0;
    for i in 1..n {
        if apples[i].abs() < apples[min].abs() {
            min = i;
        }
    }
    let sum : i32 = apples.iter().sum();
    println!("{}", sum - apples[min]);
}


Measured memory_bytes: 4352
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

  vector<char> v;
  for (int i = 0; i < s.size(); ++i) {
    v.push_back(s[i]);
  }

  v.erase(unique(all(v)), v.end());
  cout << v.size() - 1 << endl;

  return 0;
}


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

int main(){
  int N,max = 0;
  bool flag = true;
  cin >> N;
  vector<int> H(N);
  
  for(int i = 0;i < N;i++){
    cin >> H.at(i);
  }
  
  for(int i = 0;i < N;i++){
    
    if(H.at(i) > max){
      max = H.at(i);
    }else if(H.at(i) < max - 1){
      flag = false;
    }
  }
  
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

#define MAX_VERTEX 100
#define INF 1000000

int vertex_num; // ???????????°
int d[MAX_VERTEX][MAX_VERTEX];  // ???????????¢???d[?§????][??????]??§?§??????????????????????????????¢?????¨???

void Input() {
  cin >> vertex_num;

  // (a1) ??\???????????¶??§?????????
  // d?????¨???INF?????????????§??????¨????????????????????´???0
  for (int i = 0; i < vertex_num; i++){
	  for (int j = 0; j < vertex_num; j++){
		  if(i==j){
		  	d[i][j]=0;
		  	}else{
		  	d[i][j]=INF;
		  	}
	  }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }
}

void WarshallFloyd() {
	// (b1)?§£??¬?????????????????????
	for (int k = 0; k < vertex_num; k++){
		for (int i = 0; i < vertex_num; i++){
			for (int j = 0; j < vertex_num; j++){
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}

	}
}

void Output() {
  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[0][i] << endl;
  }
}

int main() {

  Input();
  WarshallFloyd();
  Output();

  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct Size {
  int r, c;
};

int main() {
  int n;
  cin >> n;
  vector<Size> M(n);
  for (int i = 0; i < (int)(n); ++i) cin >> M[i].r >> M[i].c;

  const int INF = 1e9;
  vector<vector<int> > dp(n, vector<int>(n, INF));
  for (int i = 0; i < (int)(n); ++i) dp[i][i] = 0;

  for (int l = 2; l <= n; ++l) {
    for (int i = 0; i < (int)(n); ++i) {
      int j = i + l - 1;
      if (j >= n) continue;
      for (int k = i; k + 1 <= j; ++k) {
        chmin(dp[i][j], dp[i][k] + dp[k + 1][j] + M[i].r * M[k].c * M[j].c);
      }
    }
  }

  cout << dp[0][n - 1] << endl;

  return 0;
}



Measured memory_bytes: 3172
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n,ans;cin>>n;
  vll a(n),b(n),c(n);
  rep(i,0,n){
    cin>>a[i];
  }
  rep(i,0,n){
    cin>>b[i];
  }
  rep(i,0,n){
    cin>>c[i];
  }
  sort(a.begin(),a.end());sort(c.begin(),c.end());
  rep(i,0,n){
    auto it=lower_bound(a.begin(),a.end(),b[i]);
    ll tmp=it-a.begin();
    auto it2=upper_bound(c.begin(),c.end(),b[i]);
    ans+=tmp*(c.end()-it2);
  }
  out(ans);
}


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

int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i,n) cin >> w.at(i);
    set<string> dict;
    
    rep(i, n) {
        if(dict.count(w.at(i))) {
            cout << "No" << endl;
            return 0;
        }
        if(0 < i) {
            char last = w.at(i-1)[w.at(i-1).size()-1];
            char first = w.at(i)[0];
            if(last != first) {
                cout << "No" << endl;
                return 0;
            }
        }
        dict.insert(w.at(i));
    }
    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	ll n,q; cin>>n>>q;
	vector<ll> s( n, 0 );
	vector<ll> t( n, 0 );
	vector<ll> x( n, 0 );
	REP(i,n) cin>>s[i]>>t[i]>>x[i];
	vector<ll> d( q, 0 );
	REP(i,q) cin>>d[i];

	using P = pair<ll,ll>;
	vector<P> event;
	REP( i, n )
	{
		event.push_back( {s[i] - x[i], x[i]} );
		event.push_back( {t[i] - x[i], -x[i]} );
	}
	sort( ALL( event ) );

	set<ll> stop;
	ll dIdx = 0;
	REP(i,event.size())
	{
		while( dIdx < q && event[i].first > d[dIdx] )
		{
			if( stop.size() == 0 ) cout << -1 << endl;
			else cout << *stop.begin() << endl;
			++dIdx;
		}
		if( event[i].second > 0 ) stop.insert( event[i].second );
		else stop.erase( -event[i].second );
	}
	for( ll dd = dIdx; dd < q; ++dd ) cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 25192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

const int MX = 1e6;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	vector<bool> good(MX+1, true);
	vi v(n), cnt(MX+1);
	
	for(int i=0; i<n; ++i) {
		cin >> v[i];
		++cnt[v[i]];
	}
	
	
	for(int i=1; i<=MX; ++i) {
		if(cnt[i]>0) {
			for(int j=2*i; j<=MX; j+=i) good[j]=false;
		}
	}
	
	int ans=0;
	
	for(auto x: v) {
		if(cnt[x]==1 && good[x]) ++ans;
	}
	
	cout << ans << "\n";
	
	return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  int sum=0;
  for(int i=0; i<m; i++){
    int x;
    cin >> x;
    sum += x;
  }
  int ans=n-sum;
  if(ans<0) ans=-1;
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int h;
    cin>>h;
    int n;
    cin>>n;
    if(h%n==0){
        cout<<h/n<<endl;
    }
    else{
        cout<<h/n+1<<endl;
    }
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto s = sread();
    auto a = s[0 .. $ - 1].all!(c => c == s[0]);
    auto b = s[1 .. $].all!(c => c == s[1]);
    writeln((a || b) ? "Yes" : "No");
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long a = 1, b = 1;
	for (int i = 0; i < n; i++) {
		int s, t;
		cin >> s >> t;

		long long g = max((a + s - 1) / s, (b + t - 1) / t);
		a = g * s;
		b = g * t;
	}
	cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (){
	int k;
	int length = 0;
	scanf("%d", &k);
	char s[100];
	scanf("%s", s);
	for(int i = 0; s[i] != '\0'; i++){
		length++;
	}
	if(length <= k){
		printf("%s", s);
	}
	else{
		for(int i = k; i <= k + 3; i++){
			if(i < k + 3){
				s[i] = '.';
			}
			else{
				s[i] = '\0';
			}
		}
		printf("%s", s);
	}
	return 0;
}


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

using namespace std;

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if ((i < B) xor (j < A))
                cout << 0;
            else
                cout << 1;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
def io_tmp():
    global input
    import io, sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline

io_tmp()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1, t-1] = graph[t-1, s-1] = w
floyd_warshall(graph, directed=False, overwrite=True)
dist = floyd_warshall(graph <= L, directed=False)
dist[np.isinf(dist)] = 0.0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(dist[s-1][t-1]) - 1)
print(*ans, sep='\n')


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define forup(i,a,b) for(int i=(a); i<(b); ++i)
#define fordn(i,a,b) for(int i=(a); i>(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)

#define gi(x) scanf("%d",&x)
#define gl(x) cin>>x
#define gd(x) scanf("%lf",&x)
#define gs(x) scanf(" %s",x)

#define D(x) cout << #x << " : " << x << endl

#define fs first
#define sc second

#define pb push_back
#define mp make_pair

const int inf=numeric_limits<int>::max();
const int ninf=numeric_limits<int>::min();
const LL linf=numeric_limits<LL>::max();

const int max_n=100001, max_m=100001;

int n, m, dist[max_n], indeg[max_n], topo[max_n], curr;
vector<int> graph[max_n];
vector<int> graphT[max_n];
bool visited[max_n];

void dfs(int i){
    visited[i] = true;
    for(auto &neighbour : graph[i]){
        if(!visited[neighbour]){
            dfs(neighbour);
        }
    }
    topo[curr--] = i;
}

int main() {
    int p, q, mx;
    gl(n>>m);
    rep(i,m){
        gl(p>>q);
        indeg[q]++;
        graph[p].pb(q);
        graphT[q].pb(p);
    }
    curr = n;
    rep(i,n+1){
        if(!indeg[i]){
            dfs(i);
            dist[i] = 0;
        }
        else{
            dist[i] = ninf;
        }
    }
    rep(i,n+1){
        if(dist[topo[i]]==ninf){
            mx = ninf;
            for(auto &neighbour : graphT[topo[i]]){
                mx = max(mx, dist[neighbour]);
            }
            dist[topo[i]] = 1+mx;
        }
    }

    cout << *max_element(dist, dist+n+1) << endl;
    return 0;
}

Measured memory_bytes: 15616
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static Int64 Lcm(Int64 a, Int64 b)
    {
        return a / Gcd(a, b) * b;
    }

    static Int64 Gcd(Int64 m, Int64 n)
    {
        if (n == 0) return m;
        return Gcd(n, m % n);
    }

    static void Main(String[] args)
    {
        var n = Int32.Parse(Console.ReadLine());
        var res = Int64.Parse(Console.ReadLine()); 

        for (var i = 0; n - 1 > i; i++)
        {
            res = Lcm(res, Int64.Parse(Console.ReadLine()));
        }
        Console.WriteLine(res);
    }
}


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

int main(void) {
  char a, b;
	cin >> a >> b;
  if(a == 'D'){
		if(b == 'H') cout << "D" << endl;
		else cout << "H" << endl;
	}else{
		cout << b << endl;
	}
}


Measured memory_bytes: 256
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 2e5 + 5;

ll tree[6*N];
ll pend[6*N];

void apply(int idx, int s, ll v){
    tree[idx] += s * v;
    pend[idx] += v;
}
void prop(int idx, int sl, int sr){
    if(pend[idx] != 0){
        apply(idx<<1, sl, pend[idx]);
        apply(idx<<1|1, sr, pend[idx]);
        pend[idx] = 0;
    }
}
void update(int idx, int left, int right, int l, int r, ll v){
    if(left >= l && right <= r){
        apply(idx, right-left+1, v);
    }else if(right < l || left > r){
        // do nothing
    }else{
        int mid = (left+right)/2;
        prop(idx, mid-left+1, right-mid);
        update(idx<<1, left, mid, l, r, v);
        update(idx<<1|1, mid+1, right, l, r, v);
        tree[idx] = tree[idx<<1] + tree[idx<<1|1];
    }
}

int n;
vi lst[N];

int p[N];
int cek(int x){
    if(p[p[x]] != p[x])p[x] = cek(p[x]);
    return p[x];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n;
    REP(i,1,n-1){
        int a,b;
        cin>>a>>b;
        lst[a].pb(b);
        lst[b].pb(a);
    }

    REP(i,1,n)p[i] = i;

    // build for 1
    int curr = 0;
    REP(i,1,n){
        curr++;

        for(auto to : lst[i]){
            if(to < i){
                if(cek(i) != cek(to)){
                    curr--;
                    p[cek(to)] = cek(i);
                }
            }
        }

        update(1, 1, n, i, i, curr);
    }

    ll ans = 0;
    REP(i,1,n){
        ans += tree[1];

        // exclude i
        update(1, 1, n, i, n, -1);

        for(auto to : lst[i]){
            if(to > i){
                update(1, 1, n, to, n, 1);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 23784
#pragma GCC optimize("Ofast", "unroll-loops")

// #define TEST

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll MOD = 998244353LL;

template<typename T>
struct SegmentTree {
private:
	int sz, n;
	vector<T> data;
	function<T(T, T)> f;
	T identity_element;
public:
	/* constructor */
	SegmentTree(
		vector<T> v, // initial data
		T identity_element, // identity element
		function<T(T, T)> f // operation
	) {
		sz = v.size();
		n = 1; while (n < sz) n <<= 1;
		this->f = f;
		this->identity_element = identity_element;
		data.resize(2 * n - 1, identity_element);
		for (int i = 0; i < sz; ++i)
			data[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; --i)
			data[i] = f(data[2 * i + 1], data[2 * i + 2]);
	}
	/* update query */
	void update(int idx, const T val) {
		idx += n - 1;
		data[idx] = val;
		while (idx) {
			idx = (idx - 1) >> 1;
			data[idx] = f(data[2 * idx + 1], data[2 * idx + 2]);
		}
	}
	/* get query */
	T get(int left, int right, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= left || right <= l) return identity_element;
		if (left <= l && r <= right) return data[k];
		T val_l = get(left, right, 2 * k + 1, l, (l + r) / 2);
		T val_r = get(left, right, 2 * k + 2, (l + r) / 2, r);
		return f(val_l, val_r);
	}
};

int main() {
	int N; cin >> N;
	vector<pair<int, int>> xd(N);
	for (int i = 0; i < N; ++i)
		cin >> xd[i].first >> xd[i].second;
	sort(xd.begin(), xd.end());

	SegmentTree<int> seg(
		vector<int>(N, 0), 0,
		[&](auto a, auto b) {return max(a, b); }
	);
	seg.update(N - 1, N - 1);
	for (int i = N - 2; i >= 0; --i) {
		int reach = xd[i].first + xd[i].second;
		pair<int, int> tmp = { reach, 0 };
		auto iter = lower_bound(xd.begin(), xd.end(), tmp);
		if (iter == xd.begin() + i + 1)
			seg.update(i, i);
		else
			seg.update(i, seg.get(i + 1, iter - xd.begin()));
	}
#ifdef TEST
	cout << "-----seg-----" << endl;
	for (int i = 0; i < N; ++i)
		cout << seg.get(i, i + 1) << " ";
	cout << endl;
#endif
	vector<ll> dp(N + 1, 1);
	for (int i = N - 1; i >= 0; --i) {
		dp[i] = (dp[seg.get(i, i + 1) + 1] + dp[i + 1]) % MOD;
	}
#ifdef TEST
	cout << "-----dp-----" << endl;
	for (auto i : dp) cout << i << " ";
	cout << endl;
#endif
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S == "SUN") {
    cout << 7 << endl;
  }
  if(S == "MON") {
    cout << 6 << endl;
  }
  if(S == "TUE") {
    cout << 5 << endl;
  }
  if(S == "WED") {
    cout << 4 << endl;
  }
  if(S == "THU") {
    cout << 3 << endl;
  }
  if(S == "FRI") {
    cout << 2 << endl;
  }
  if(S == "SAT") {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#import numpy as np

n = list(input())
n_size = len(n)
count = 0
#print(n_size)  
new_list = []
new_list.append(int(n[0]))
for i in range(n_size-1):
  if new_list[i] == 0:
    new_list.append(1)
  else:
    new_list.append(0)

#print(new_list)
    
for i in range(n_size):
  if (int(n[i]) != int(new_list[i])):
    count+=1

#print(new_list)    
if n_size == 1:
  print(0)
else:
#  ans = n_size-count    
  print(count) 

Measured memory_bytes: 4652
# ABC 065: B – Trained?
n = int(input())
a = [int(input()) for _ in range(n)]
lighting = 1
number = 0

for i in range(n):
    if lighting == 2:
        print(number)
        break
    else:
        number += 1
        lighting = a[lighting - 1]
else:
    print(-1)

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

ll nC2(ll n)
{
  return n * (n - 1) / 2;
}

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

  int n;
  cin >> n;

  int a[n];
  map<int,int> mp;

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

  ll ans = 0;
  for (auto e : mp) ans += nC2(e.second);

  for (int i = 0; i < n; ++i) cout << ans - (mp[a[i]] - 1) << '\n';

  return (0);
}


Measured memory_bytes: 10304
n=int(input())
a=[int(i) for i in ("0 "+input()+" 0").split()]
ans=sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
  print(ans-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))

Measured memory_bytes: 14176
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val txy = (1..n).map { Triple(sc.nextInt(), sc.nextInt(), sc.nextInt()) }

  var preT = 0
  var preX = 0
  var preY = 0

  for (txyi in txy) {
    val t = txyi.first
    val x = txyi.second
    val y = txyi.third

    val time = t - preT
    val distX = Math.abs(x - preX)
    val distY = Math.abs(y - preY)

    val dist = distX + distY
    if (time < dist) {
      println("No")
      return
    }

    if (time % 2 != dist % 2) {
      println("No")
      return
    }


    preT = t
    preX = x
    preY = y
  }

  println("Yes")

}


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

int main() {
	int n,T;
  cin>>n>>T;
  vector<int> vecC(n);
  vector<int> vecT(n);
  
  for(int i=0;i<n;i++){
  	cin >> vecC.at(i);
    cin >> vecT.at(i);
  }
  int ans =10000;
  for(int i=0;i<n;i++){
  	if(vecT.at(i)<=T){
    	ans = min({ans,vecC.at(i)});
    }
  }
  if(ans!=10000)
  cout<<ans<<endl;
  else
    cout<<"TLE"<<endl;
  return 0;
}

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

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

	int n,a,b,c,t;
	vector <int> vv,v;
	int ret = 1000000000;

	cin >> n >> a >> b >> c;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		vv.push_back(t);
	}

	sort(vv.begin(),vv.end());
	vector <int> V = {a,b,c};
	vector <int> perm = {0,1,2};
	do
	{
		vector <int> v = vv;
		vector <int> l;
		for(int i=0;i<perm.size();i++)
		{
			//cout << perm[i] << ' ' << V[perm[i]] << '\n'; 
			l.push_back(V[perm[i]]);
		}
		int res = 0;
	for(int i=0;i<l.size();i++)
	{
		int mp = 100000000;
		vector <int> temp;
		int m = v.size();
		for(int j=1;j<(1<<m);j++)
		{
			int sum = 0;
			int spell = 0;
			vector <int> sel;
			for(int k=0;k<m;k++)
			{
				if(j&(1<<k))
				{
					spell++;
					sum += v[k];
					sel.push_back(k);
				}
			}
			int mpp = abs(sum-l[i]) + (spell-1)*10;
			if(mpp < mp)
			{
				mp = mpp;
				temp = sel;
			}
		}
		res+=mp;
		for(int j=temp.size()-1;j>=0;j--)
		{
			v.erase(v.begin()+temp[j]);
		}
	}
	ret = min(ret,res);
	}while(next_permutation(perm.begin(),perm.end()));

	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 256
from collections import deque

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

aa = deque(sorted(a, reverse=True))
ans = aa.popleft()
for i in range(n-2):
    if i % 2 == 0:
        comf = aa.popleft()
    ans += comf
    #print(ans)
print(ans)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, mod = 1e9 + 7;
typedef long long ll;
ll qkpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
struct node {
    ll x, y;
}a[maxn];
int main() {
    ll n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y;
    }
    ll maxn[10], minn[10];
    for (int i = 0; i < 6; i++) maxn[i] = -1e16, minn[i] = 1e16;
    for(int i=0;i<n;i++)
	{
		maxn[0]=max(maxn[0],a[i].x-a[i].y);
		maxn[1]=max(maxn[1],a[i].x+a[i].y);
		maxn[2]=max(maxn[2],-a[i].x+a[i].y);
		maxn[3]=max(maxn[3],-a[i].x-a[i].y);
		minn[0]=min(minn[0],a[i].x-a[i].y);
		minn[1]=min(minn[1],a[i].x+a[i].y);
		minn[2]=min(minn[2],-a[i].x+a[i].y);
		minn[3]=min(minn[3],-a[i].x-a[i].y);
	}
	ll ans = 0;
	for (int i = 0; i < 4; i++) {
        ans = max(ans, maxn[i] - minn[i]);
	}
	cout << ans;
}


Measured memory_bytes: 6752
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <ctime>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
char s[MAXN];
int tag[MAXN];

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    scanf("%s", s);
    int cnt = 0;
    vector<int> psum;
    psum.push_back(0);
    for (int i = 0; i < N; i++) {
        if (!i || s[i] == s[i - 1]) cnt++;
        else {
           if (s[i - 1] == '1') tag[psum.size()] = 1;
           psum.push_back(psum.back() + cnt);
           cnt = 1;
        }
    }
    if (s[N - 1] == '1') tag[psum.size()] = 1;
    psum.push_back(psum.back() + cnt);
    int ans = 0;
    for (int i = 1; i < (int)psum.size(); i++) {
        int req = 0;
        if (tag[i]) req = 1 + 2 * K;
        else req = 2 * K;
        int cur = psum[i] - psum[max(0, i - req)];
        ans = max(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 105;
long long M= 1000000007;

int main() {
	int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<a[1]-a[0]+a[2]-a[1];
	
}


Measured memory_bytes: 256
using System;
public class Eratosthenes
{
	public static void Main(string[] args)
	{
		int count = int.Parse(Console.ReadLine());
		int sum = 0;//?´???°???????¨?
		
		for (int i = 0; i < count; i++)
		{
			//?????????????±????????????????
			int target = int.Parse(Console.ReadLine());
			//????????????
			//target???3??\????????£???????????§??????????????????if?????????????????\????????????
			
			 if (target > 3 & target % 2 != 0) 
			{
				
				int j = 3;
				do{				
					if (target % j == 0)
					{//?´???°??§?????????
						break;
					}
					
					
					j+=2;
				}while(j<=target/j);
				if (j  > target / j)
					{
						//break?????????????????´????????????????????\???
						sum ++;
						
					}
				
			}
			else if(target==2|target==3)
			{//???????????¶??§????????§??????????????????????????§?????????????????????????????¶???????????????????????§???????????????????????????????????????
				//??????????????????????????????????????????
				sum++;
				
			}
		}
		
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 9172
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int main() {
    int n, w, h;
    cin >> h >> w >> n;
    cout << (n - 1) / max(h, w) + 1 << endl;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
A = [[0]*W for i in range(H)]
k = 0
c = 0
As = []
for i in range(H):
  ss = input()
  ws = ss.split("#")
  if len(ws) > 1:
    w0 = ws.pop()
    ws[-1] += w0
    As = []
    j = 0
    for w in ws:
      l = len(w)+1
      for jj in range(l):
        As.append(k+1)
      k += 1
    for ii in range(c+1):
      print(" ".join(map(str, As)))
    c = 0
  else:
    c += 1
for ii in range(c):
  print(" ".join(map(str, As)))
c = 0


Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const double EPS = 1e-10;

int main(void)
{
    string S, T;
    cin >> S >> T;

    int cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != T[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return (0);
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> lis(N);
    vector<pair<ll, ll>> a(M);
    rep(i, M)
    {
        cin >> a[i].first >> a[i].second;
        a[i].first--;
        lis[a[i].first].emplace_back(a[i].second);
    }
    rep(i, N)
    {
        sort(lis[i].begin(), lis[i].end());
    }
    rep(i, M)
    {
        ll v = a[i].first;
        ll id = lower_bound(lis[v].begin(), lis[v].end(), a[i].second) - lis[v].begin();
        printf("%06lld", v + 1);
        printf("%06lld\n", id + 1);
    }
}

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

const int N = 2e5;
int par[N];
int par2[N];
vector<int> items[N];

void init() {
    for (int i = 0; i < N; i++) {
        par[i] = i;
        par2[i] = i;
    }
}

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

void unite(int x, int y) {
    par[find(x)] = find(y);
}

int find2(int x) {
    if (x == par2[x]) {
        return x;
    }
    return par2[x] = find2(par2[x]);
}

void unite2(int x, int y) {
    x = find2(x);
    y = find2(y);
    if (x == y) {
        return;
    }
    if (items[x].size() < items[y].size()) {
        swap(x, y);
    }
    for (int e : items[y]) {
        items[x].push_back(e);
    }
    par2[y] = x;
}

int main() {
    int n, K, L;
    cin >> n >> K >> L;

    init();

    for (int i = 0; i < K; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        unite(u, v);
    }

    for (int i = 0; i < N; i++) {
        items[i].push_back(find(i));
    }

    for (int i = 0; i < L; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        unite2(u, v);
    }

    for (int i = 0; i < N; i++) {
        sort(items[i].begin(), items[i].end());
    }

    for (int i = 0; i < n; i++) {
        int u = find2(i);
        int s = upper_bound(items[u].begin(), items[u].end(), find(i)) - lower_bound(items[u].begin(), items[u].end(), find(i));
        printf("%d ", s);
    }
}


Measured memory_bytes: 13704
let mod = 1000000007
let input = readLine()!.split(separator: " ").map { Int($0)! }

let H = input[0]
let W = input[1]

var grid: [[Character]] = .init(repeating: .init(repeating: "@", count: W), count: H)

for h in 0..<H {
  grid[h] = Array(readLine()!)
}

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: W + 1), count: H + 1)
dp[0][0] = 1
for row in 1...H {
  for col in 1...W {
    if grid[row - 1][col - 1] == "#" {
      dp[row][col] = 0
      continue
    }
    if row == 1 && col == 1 {
      dp[row][col] = 1
      continue
    }
    dp[row][col] = (dp[row - 1][col] + dp[row][col-1]) % mod
  }
}
print(dp[H][W])

Measured memory_bytes: 31820
import scala.math

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i
  var n = sc.nextInt() % 1000
  if (n == 0){
    println(0)
    sys.exit()
  }
  println(1000 - n)
}


Measured memory_bytes: 55292
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const ll MAX = 1e9;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
ll A, B;

bool enough(vector<ll> h, ll T) {
  // まずB * Tのダメージを全ての魔物に与える
  for (int i = 0; i < N; i++) {
    h[i] -= B * T;
  }

  // 残りの体力が大きい順に、魔物に追加ダメージ(A - B)を与えていく
  ll damage = A - B;
  sort(h.begin(), h.end());
  for (int i = N - 1; i >= 0; i--) {
    if (h[i] <= 0) break;

    ll c = (h[i] + damage - 1) / damage;
    T -= c;
    if (T < 0) break;
    h[i] = 0;
  }

  // 全ての魔物の体力が0以下であればtrueを返す
  bool res = true;
  for (int i = 0; i < N; i++) if (h[i] > 0) {
    res = false;
  }

  return res;
}

int main() {
  // 入力
  cin >> N >> A >> B;
  vector<ll> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];

  // ll maxi = 0;
  // for (int i = 0; i < N; i++) maxi = max(maxi, h[i]);

  // 何回の爆発で魔物を全滅させられるかについて二分探索
  ll ans;
  ll l = 0, r = MAX;
  while (l <= r) {
    ll mid = (l + r) / 2;

    if (enough(h, mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define itn int
typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int a;
  cin >> a;
  if (a <= 999) {
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll n,m,i,j;
     cin>>n>>m;

     ll height[n+1];
     for(i=1;i<=n;i++)
     {
         cin>>height[i];
     }

     map<ll,vector<ll>>adj;

     for(i=0;i<m;i++)
     {
         ll a,b;
         cin>>a>>b;
         adj[a].pb(b);
         adj[b].pb(a);
     }

     ll ans = n-adj.size();


     for(auto it=adj.begin(); it!=adj.end(); it++)
     {
         ll p = it->first;
         ll ht = height[p];
         ll flag=0;
         for(j=0;j<adj[p].size();j++)
         {
             //cout<<adj[p][j]<<" ";
             if(height[adj[p][j]]>=ht)
             {
                 flag=1;
                 break;
             }
         }
         if(!flag)
         {
             ans++;
         }
     }

     cout<<ans<<endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int h, w, m;
map<pair<int, int>, bool> here;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> h >> w >> m;
	vector<pii> rows, cols;
	rep(i, 0, h) {
		rows.push_back({0, i});
	}
	
	rep(i, 0, w) {
		cols.push_back({0, i});
	}
	
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		here[{a, b}] = true;
		++rows[a].first;
		++cols[b].first;
	}
	sort(all(rows), greater<pii>());
	sort(all(cols), greater<pii>());
	int max = rows[0].first + cols[0].first;
	bool inter = true;
	rep(i, 0, sz(rows)) {
		if (rows[i].first != rows[0].first) break;
		if (!inter) break;
		rep(j, 0, sz(cols)) {
			if (rows[i].first + cols[j].first < max) break;
			if (!here[{rows[i].second, cols[j].second}]) {
				inter = false;
				break;
			}
		}
	}
	cout << max - (inter);
}


Measured memory_bytes: 26564
M, D = map(int, input().split())
count = 0
if D < 22:
    print(0)
else:
    a = D // 10
    b = D - a * 10
    if b < 2:
        a -= 1
        b = 9 
    for i in range(2, a):
        for j in range(2, 10):
            if i * j <= M and i * j >= 4:
                count += 1
    for k in range(2, b+1):
        if a * k <= M and a * k >= 4:
            count += 1
    print(count) 


Measured memory_bytes: 3060
#include<iostream>

using namespace std;

void printing(int N,int s[],int sum) {

	for (int i = 0; i < N; i++) {

		if (s[i] % 10 != 0) {

			cout << sum - s[i] << endl;
			return;

		}

	}

	cout << 0 << endl;
	return;

}

int main() {

	int N = 0;
	int s[100] = {};
	int sum = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {

		cin >> s[i];
		sum += s[i];

	}

	for (int i = N - 2; i >= 0; i--) {

		for (int u = 0; u <= i; u++) {
			
			int temp = 0;

			if (s[u] > s[u + 1]) {

				temp = s[u];
				s[u] = s[u + 1];
				s[u + 1] = temp;

			}

		}

	}

	if (sum % 10 == 0) {

		printing(N, s, sum);

	}
	else {

		cout << sum << endl;

	}

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

struct edge {
  int dst;
  long long cost;
};

int main(){
  int N;
  scanf("%d", &N);
  int a, b, c;
  std::vector<edge > edges[N];
  for (int i=0; i<N-1; i++){
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    a--;
    b--;
    struct edge thisedge = {b, (long long)c};
    edges[a].push_back(thisedge);
    thisedge.dst = a;
    edges[b].push_back(thisedge);
  }
  int Q, K;
  scanf("%d", &Q);
  scanf("%d", &K);
  K--;
  std::vector<int > x(Q), y(Q);
  for (int i=0; i<Q; i++){
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
    x[i]--;
    y[i]--;
  }
  std::priority_queue<int > queue;
  queue.push(K);
  std::vector<long long > dist(N+4, 1e15);
  dist[K]=0;
  while(queue.size()>0){
    int src = queue.top();
    queue.pop();
    for (int i=0; i<edges[src].size(); i++){
      int dst = edges[src][i].dst;
      if (dist[dst]>dist[src]+edges[src][i].cost){
        dist[dst] = dist[src]+edges[src][i].cost;
        queue.push(dst);
      }
    }
  }

  for (int i=0; i<Q; i++){
    printf("%lld\n", dist[x[i]]+dist[y[i]]);
  }
  return 0;
}


Measured memory_bytes: 10864
H,W,K = map(int,input().split())
table = []

for _ in range(H):
    table.append(input())

ans = 0
for i in range(2**H):
    for j in range(2**W):
        black = 0
        for k in range(H):
            for l in range(W):
                if ((i >> k) & 1) == 0 and ((j >> l) & 1) == 0 and table[k][l] == '#':
                    black += 1
        
        if black == K:
            ans += 1

print(ans)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string o, e;
  cin >> o >> e;
  for (int i = 0; i < e.size(); i++) {
    cout << o[i] << e[i];
  }
  if (o.size() != e.size()) cout << o[o.size() - 1];
  cout << endl;
  return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3


def main():
    n, Y = map(int, input().split())
    ans = [-1, -1, -1]

    for x in range(n + 1):
        for y in range(n - x + 1):
            if x * 10000 + y * 5000 + (n - x - y) * 1000 == Y:
                ans = [x, y, (n - x - y)]
                break
    print(*ans)

main()


Measured memory_bytes: 3060
import sys
range = xrange
input = raw_input

class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n

    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a

            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
k = inp[ii]; ii += 1

count = [-1]*n

dsu = DisjointSetUnion(n)
for _ in range(m):
    a = inp[ii] - 1; ii += 1
    b = inp[ii] - 1; ii += 1
    dsu.union(a,b)
    count[a] -= 1
    count[b] -= 1

for _ in range(k):
    a = inp[ii] - 1; ii += 1
    b = inp[ii] - 1; ii += 1
    if dsu.find(a) == dsu.find(b):
        count[a] -= 1
        count[b] -= 1

for a in range(n):
    count[a] += dsu.size[dsu.find(a)]

print ' '.join(str(x) for x in count)


Measured memory_bytes: 71700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	const int x = a % 2, y = b % 2, z = c % 2;
	int answer = 0;
	if(x == y && x != z){
		++a; ++b; ++answer;
	}else if(x == z && x != y){
		++a; ++c; ++answer;
	}else if(y == z && y != x){
		++b; ++c; ++answer;
	}
	const int maxval = max(max(a, b), c);
	answer += (maxval - a) / 2;
	answer += (maxval - b) / 2;
	answer += (maxval - c) / 2;
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256