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

int main(void){
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b,b+n);
    int c = 0;
    for(int i = 0;i < n;i++){
        if(a[i] != b[i])c++;
    }
    if(c > 2)cout << "NO";
    else cout << "YES";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> d(n);
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }
    sort(all(d));

    int minval = d[n/2 - 1];
    int maxval = d[n/2];
    ll ans = max(0, maxval - minval);
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1024
num  = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

if(num == 2)
  puts (a[0] - a[1]).abs
  exit 0
end

total = a.inject(&:+)

sunuke = 0
kuma = total
min = 10**9

a[0..-2].each do |i|
  sunuke += i
  kuma -= i
  diff = (sunuke - kuma).abs
  
  if(diff == 0)
    puts 0
     exit 0
  elsif(diff < min)
    min = diff
  end
end

puts min

Measured memory_bytes: 16516
#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 <set>
#include <deque>

int main(){
  std::string S;
  std::cin >> S;
  std::string s1="dream";
  std::string s2="dreamer";
  std::string s3="erase";
  std::string s4="eraser";
  int s1length = s1.length();
  int s2length = s2.length();
  int s3length = s3.length();
  int s4length = s4.length();
  int i=S.length()-1;
  while(i>=0){
    //printf("i=%d\n", i);
    //printf("i-s1.length()+1=%d\n", i-s1length+1);
    bool find = false;
    //std::cout << "cheing cond1" << std::endl;
    //std::cout << S.substr(i-s1length+1,s1length) << std::endl;
    if (i-s1length+1>=0){    
      if (S.substr(i-s1length+1,s1length)==s1){
        //std::cout << "cond1" << std::endl;
        i -= s1length;
        find = true;
      }
    }
    //std::cout << "cheing cond2" << std::endl;
    if (i-s2length+1>=0){
      //std::cout << i-s2length+1 << std::endl;
      //std::cout << S.substr(i-s2length+1,s2length) << std::endl;
      if (S.substr(i-s2length+1,s2length)==s2){
        //std::cout << "cond2" << std::endl;
        i -= s2length;      
        find = true;
      }
    }
    //std::cout << "cheing cond3" << std::endl;
    if (i-s3length+1>=0){
      if (S.substr(i-s3length+1,s3length)==s3){
        // std::cout << "cond3" << std::endl;
        i -= s3length;
        find = true;
      }
    }
    //std::cout << "cheing cond4" << std::endl;
    if (i-s4length+1>=0){
      if (S.substr(i-s4length+1,s4length)==s4){ 
        //std::cout << "cond4" << std::endl;
        i -= s4.length();
        find = true;
      }
    }
    if (!find){
      printf("NO\n");
      return 0;
    }    
  }
  printf("YES\n");

  return 0;
}


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

const int INF = 1e+9;

struct edge {int from, to, C;};

int BellmanFord(vector<edge>& G, vector<int>& d,
                 vector<bool>& reachable_from_1, 
                 vector<bool>& reachable_from_N, int N, int M){
    d[0] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            edge e = G[j];
            if(!reachable_from_1[e.to] or !reachable_from_N[e.to]) continue; 
            if(!reachable_from_1[e.from] or !reachable_from_N[e.from]) continue; 
            if(d[e.to] > d[e.from]+e.C){
                d[e.to] = d[e.from]+e.C;
                if(i == N-1) return -1;
            }
        }
    }
    return 0;
}

void dfs(int pos, vector<vector<int>>& G, vector<bool>& reachable){
    if(reachable[pos]) return;
    reachable[pos] = true;
    for(int v: G[pos]){
        dfs(v, G, reachable);
    }
}


int main()
{
    int N, M, P;
    cin >> N >> M >> P;
    vector<edge> edges(M);
    vector<vector<int>> G(N), rG(N); 
    for( int i = 0; i < M; ++i ){
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;
        edges[i] = {A, B, -(C-P)};
        G[A].push_back(B);
        rG[B].push_back(A);
    }

    // Preprocess
    // 1 -> N の間に存在しない頂点を見つける
    vector<bool> reachable_from_1(N, false), reachable_from_N(N, false);
    dfs(0, G, reachable_from_1);
    dfs(N-1, rG, reachable_from_N);

    // Bellman Ford
    vector<int> d(N, INF);
    int ret = BellmanFord(edges, d, reachable_from_1, reachable_from_N, N, M);

    if(ret == -1) cout << -1 << endl;
    else cout << max(-d[N-1], 0) << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
    int k, a, b;
    cin >> k;
    cin >> a >> b;
    
    int c = 0;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) c++;
    }
    
    if(c) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define N 100
#define white 0
#define gray 1
#define black 2
int h, qpt1 = 0, qpt2 = 0;
int A[N][N], color[N], d[N], Q[N];

void enq(int u) {
  Q[++qpt1] = u;
}

int deq(void) {
  int u = Q[++qpt2];
  return u;
}

void bfs(void) {
  int s = 0;
  int u;
  for ( int i = 0; i < h; ++i ) {
    color[i] = white;
    d[i] = -1;
  }
  color[s] = gray;
  d[s] = 0;
  enq(s);

  while ( qpt1 != qpt2 ) {
    u = deq();
    for ( int v = 0; v < h; ++v) {
      if ( A[u][v] && color[v] == white) {
        color[v] = gray;
        d[v] = d[u] + 1;
        enq(v);
      }
    }
    color[u] = black;
  }
}

void print(void) {
  for ( int i = 0; i < h; ++i ) {
    printf("%d %d", i + 1, d[i]);
    putchar('\n');
  }
}

int main(void) {
  int a, b, v;
  scanf("%d", &h);
  for ( int i = 0; i < h; ++i ) {
    scanf("%d%d", &a, &b);
    a--;
    for ( int j = 0; j < b; ++j ) {
      scanf("%d", &v);
      v--; 
      A[a][v] = 1;
    }
  }
  bfs();
  print();
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    int n; cin >> n;
    vector<pair<int,int>> task;
    REP (i,n) {
        int a,b; cin >> a >> b;
        task.pb({b,a});
    }
    sort(ALL(task));
    int tmp = 0;
    bool ok = true;
    for (auto&& ta : task) {
        // cout << ta.first << " " << ta.second << endl;
        if (ta.first - ta.second < tmp) {
            ok = false;
        }
        tmp += ta.second;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


Measured memory_bytes: 6128
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct WeightedGraph {
  graph: Vec<Vec<(usize, i64, i64)>>,
  cdv: Vec<(i64, i64)>,
  v: usize,
}

type WeightedEdge = (usize, usize, i64, i64);
impl WeightedGraph {
  pub const INF: i64 = 1 << 60;
  pub const MAX_S: i64 = 50 * 50 + 5;

  pub fn new(edges: &[WeightedEdge], cdv: Vec<(i64, i64)>, v: usize) -> Self {
    let mut graph = vec![Vec::new(); v];
    for &(u, v, a, b) in edges {
      graph[u].push((v, a, b));
      graph[v].push((u, a, b));
    }
    Self { graph, cdv, v }
  }

  pub fn shortest_path(&self, start: usize, s: i64) -> Vec<Vec<i64>> {
    let mut dp = vec![vec![Self::INF; (Self::MAX_S + 5) as usize]; self.v];
    let mut heap = std::collections::BinaryHeap::new();

    let s = std::cmp::min(s, Self::MAX_S);
    dp[start][s as usize] = 0;
    // (時間, 頂点, 銀貨)
    heap.push(std::cmp::Reverse((0_i64, start, s)));
    while let Some(std::cmp::Reverse((cost, u, s))) = heap.pop() {
      if cost > dp[u][s as usize] {
        continue;
      }
      // 交換
      self.push(
        u,
        s + self.cdv[u].0,
        cost + self.cdv[u].1,
        &mut heap,
        &mut dp,
      );
      for &(v, a, b) in &self.graph[u] {
        if s < a {
          continue;
        }
        let new_s = s - a;
        let new_cost = cost + b;
        self.push(v, new_s, new_cost, &mut heap, &mut dp);
      }
    }
    dp
  }

  fn push(
    &self,
    u: usize,
    s: i64,
    t: i64,
    heap: &mut BinaryHeap<std::cmp::Reverse<(i64, usize, i64)>>,
    dp: &mut [Vec<i64>],
  ) {
    if s < 0 {
      return;
    }
    let s = std::cmp::min(s, Self::MAX_S);
    if dp[u][s as usize] <= t {
      return;
    }
    dp[u][s as usize] = t;
    heap.push(std::cmp::Reverse((t, u, s)));
  }
}

fn main() {
  input! {
    n: usize, m: usize, s: i64,
    edges: [(Usize1, Usize1, i64, i64); m],
    cdv: [(i64, i64); n]
  };

  let graph = WeightedGraph::new(&edges, cdv, n);
  let dp = graph.shortest_path(0, s);
  for i in 1..n {
    let res = dp[i].iter().min().unwrap();
    println!("{}", res);
  }
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>

/***** type *****/
using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
using ml = boost::multiprecision::cpp_int;

/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define mod 1000000007                           // 1e9 + 7
#define pi 3.14159265                            // 3.14 ...
#define nyan 10                                  // nyan size
/***** for each macro *****/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = Size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

/***** lambda *****/
auto Fix = [] // fix value
(auto b, auto e, auto fix)
{ for (auto it = b; it != e; ++it)* it += fix; };
auto Bit = [] // long long bit shift
(auto n) { return (1LL << n); };
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoN = [] // char to number
(auto c) { return (ll)(c - '0'); };
auto DivC = [] // long double div ceiling
(auto a, auto b) { return ceil((ld)a / (ld)b); };
auto NyaN = [] // long long nyan size
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> vvt<T> VVT
(ll ys, ll xs, T fill = T())
{	// vector<vector<T>> resize + fill
	vvt<T> v(ys);
	each(i, y, v) { y.resize(xs, fill); } return v;
}
template <class T> vvvt<T> VVVT
(ll zs, ll ys, ll xs, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	vvvt<T> v(zs);
	each(i, z, v) { z = VVT(ys, xs, fill); } return v;
}
template <class T> vt<T> InputVT
(ll size, T fix = T())
{   // input vector<T> (T != struct) + fix
	vt<T> v(size);
	each(i, e, v) { cin >> e; e += fix; } return v;
}
template <class T> vvt<T> InputVVT
(ll ys, ll xs, T fix = T())
{   // input vector<vector<T>> (T != struct) + fix
	vvt<T> v(ys); each(i, y, v) y.resize(xs);
	each(i, y, v) each(j, x, y) { cin >> x; x += fix; } return v;
}
template <class T> vvvt<T> InputVVVT
(ll zs, ll ys, ll xs, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	vvvt<T> v(zs);
	each(i, z, v) { z = InputVVT<T>(ys, xs, fix); } return v;
}

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

	ll ans = 0;
	ll d = abs(A - B) - 1;
	if (d % 2 == 0)
	{
		ans = (N - B) + (B - A) / 2 + 1;
		ans = min(ans, (A - 1) + (B - A) / 2 + 1);
	}
	else
		ans = (d + 1) / 2;

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
p = 1000000007

def remainder_of_combination(n, r, p):
    X = 1
    Y = 1
    
    for i in range(n - r +1, n + 1):
        X = X * i % p
    for i in range(1, r + 1):
        Y = Y * i % p
        
    return X * pow(Y, p-2, p)

ans = -1 + pow(2, n, p) - remainder_of_combination(n, a, p) - remainder_of_combination(n, b, p)

print(ans % p)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	s := make([]string, h)
	for i := 0; i < h; i++ {
		scanner.Scan()
		s[i] = scanner.Text()
	}
	result := ""
	for i := 0; i < h; i++ {
		for k := 0; k < w; k++ {
			str := []byte{}
			if s[i][k] == '.' {
				if 0 < i {
					str = append(str, eight(s[i-1], k, w)...)
				}
				if i < h-1 {
					str = append(str, eight(s[i+1], k, w)...)
				}
				str = append(str, eight(s[i], k, w)...)
				total := 0
				for _, s := range str {
					if s == '#' {
						total++
					}
				}
				result += strconv.Itoa(total)
			} else {
				result += "#"
			}
		}
		result += "\n"
	}
	fmt.Print(result)
}

func eight(s string, k int, w int) []byte {
	str := []byte{}
	str = append(str, s[k])
	if 0 < k {
		str = append(str, s[k-1])
	}
	if k < w-1 {
		str = append(str, s[k+1])
	}
	return str
}

Measured memory_bytes: 4480
A,B,C,X,Y = map(int,input().split())
if A+B <= C*2:
    print(A*X+B*Y)
else:
    if X >= Y:
        ans = C*2*Y
        d = X-Y
        if A <= C*2:
            ans += A*d
        else:
            ans += C*2*d
    else:
        ans = C*2*X
        d = Y-X
        if B <= C*2:
            ans += B*d
        else:
            ans += C*2*d
    print(ans)

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

#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i >= b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb push_back
#define sz(v) v.size()
#define pln(a)  cout<<a;
#define rr return 0;
#define rr1 return 1;
#define vr return;
#define int long long 

void solve()
{
  int n;
  cin>>n;
  vector<int>v(n+1);
  for0(i, n+1)  cin>>v[i];
  
  vector<int>mx(n+1);
  mx = v;
  bloop(i, n-1, 0) {
    mx[i] += mx[i+1];
  }
  
  
  int ans = 0, vi = 1;
  for0(i, n+1) {
    if(i != 0)
      vi = min(2*vi, mx[i]);
    ans += vi;
    vi -= v[i];
    if(vi < 0) {
      cout<<"-1";
      vr;
    }
  }
  
  cout<<ans;
}

signed main() {

  fio;
  
  
  //tc(t) {
    solve();
    pln("\n");
  //}
  
  rr;
}

Measured memory_bytes: 4776
#include <iostream>

using namespace std;

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

    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int arr[100005];
int arr2[100005];
//ll Pow(ll base , ll power)
//void sieve_eratosthenes(int n);
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n ;
cin>>n ;

ll  ans = (n /500)*1000 ;
 ans+=((n%500)/5)*5;
 cout<<ans<<endl;
}

/*
void sieve_eratosthenes(int n)
    {
bool primes[n+2]={false};
for(int i=3;i<=n;i+=2)
    primes[i]=1;
    primes[2]=1;
for(int i=3;i*i<=n;i+=2)
{
    if(primes[i]==1){
    for(int j=i*i;j<=n;j+=i)
        primes[j]=0;
    }
}
for(int i=2;i<=n;i++)
    if(primes[i]==1)
    cout<<i<<endl;
return;
    }
ll Pow(ll base , ll power)
        {
            if(power==0)return 1;
            ll x = Pow(base,power/2);
            x*=x;
            if(power&1)
                return base*x;
            else
                return x;
        }
*/


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

public class Solve
{
    static void Main(string[] args)
    {
        new ABC_A();
    }
}
public class ABC_A
{
    int h, w;
    char[,] c;
    ulong[,] dp;
    public ABC_A()
    {
        var line1 = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line1[0]);
        w = int.Parse(line1[1]);
        c = new char[w, h];
        dp = new ulong[w, h];
        for (int j = 0; j < h; j++)
        {
            var line2 = Console.ReadLine().Trim();
            for (int i = 0; i < w; i++)
            {
                c[i, j] = line2[i];
                dp[i, j] = ulong.MaxValue - 1;
            }
        }
        for (int j = 0; j < h; j++)
        {
            for (int i = 0; i < w; i++)
            {
                check(i, j);
            }
        }
        Console.WriteLine(dp[w - 1, h - 1]);
    }

    void check(int i, int j)
    {
        if (i == 0 && j == 0)
        { 
          dp[i, j] = (ulong)(c[i, j] == '#' ? 1 : 0);
          return;
        }
        if (j != 0)
        {
			int p = (c[i,j-1] == '.' && c[i,j] == '#') ? 1 : 0;
			dp[i,j] = Math.Min(dp[i,j-1] + (ulong)p, dp[i,j]);
        }

        if (i != 0)
        {
			int p = (c[i-1,j] == '.' && c[i,j] == '#') ? 1 : 0;
			dp[i,j] = Math.Min(dp[i-1,j] + (ulong)p, dp[i,j]);
        }
    }
}
public class ABC_B
{
    public ABC_B()
    {

    }
}
public class ABC_C
{
    public ABC_C()
    {

    }
}
public class ABC_D
{
    public ABC_D()
    {

    }
}
public class ABC_E
{
    public ABC_E()
    {

    }
}
public class ABC_F
{
    public ABC_F()
    {

    }
}


Measured memory_bytes: 13160
#include <iostream>
#include <vector>
#include <limits.h>
#include <functional>
#include <algorithm>
using namespace std;

template <typename T>
class segTree
{
    typedef function<T(T a, T b)> func;

public:
    int sz = 1;
    T lmt;
    vector<T> dat;
    func monoid;

    segTree(){};

    segTree(T a, func f, T e)
    {
        monoid = f;

        while (sz < a)
            sz <<= 1;
        dat.resize(2 * sz - 1, 0);

        for (int i = 0; i < 2 * sz - 1; i++)
            dat[i] = e;

        lmt = e;
    }

    void update(int k, T x)
    {
        k += sz - 1;
        dat[k] = x;

        while (k)
        {
            k = (k - 1) / 2;
            dat[k] = monoid(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    void show()
    {
        printf("number_of_nodes:%d\n", sz);
        for (int i = 0; i < 2 * sz - 1; i++)
        {
            if (i == sz - 1)
                printf("--array_begin--\n");
            printf("No%d:%d\n", i, dat[i]);
        }
        printf("\n--input_array--\n");
        for (int i = 0; dat[i + 1] != lmt; i++)
        {
            printf("No%d:%d\n", i, get(i));
        }
    }

    //区間[l,r)のクエリ
    T query(int l, int r)
    {
        int L = l + sz, R = r + sz;
        int ret = lmt;

        while (L < R)
        {
            if (R & 1)
            {
                R -= 1;
                ret = monoid(ret, dat[R - 1]);
            }

            if (L & 1)
            {
                ret = monoid(ret, dat[L - 1]);
                L += 1;
            }
            L >>= 1;
            R >>= 1;
        }
        //for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)printf("[%d,%d):%d\n",i,j+1,seg.rmq(i,j+1));

        return ret;
    }

private:
    T get(int a) { return dat[a + sz - 1]; }
};

main()
{
    int n, m;
    string s;
    cin >> n >> m >> s;
    reverse(begin(s), end(s));

    segTree<int> st(n + m + 1, [](int a, int b) { return a > b ? a : b; }, 0);
    for (int i = 0; i <= n; i++)
        if (s[i] == '0')
            st.update(i, i);

    vector<int> pos = {0};
    int p = 0;
    while (p < n)
    {
        int p2 = st.query(p, p + m + 1);
        if (p2 == p)
        {
            printf("-1\n");
            return 0;
        }
        p = p2;
        pos.push_back(p);
    }

    reverse(pos.begin(), pos.end());
    int sz = pos.size();
    for (int i = 0; i < sz - 1; i++)
        cout << pos[i] - pos[i + 1] << " ";
    printf("\n");
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include <stdlib.h>
int main(void){
	int N;
	int K;
	int t;
	int i, j;
	int * buffer;
	int total = 0;
	scanf("%d", &N);
	scanf("%d", &K);
	
	
	buffer =(int *) malloc(N * sizeof(int));

	for (i = 0; i < N; i++) {
		scanf("%d", &buffer[i]);
	}

	for (i = 0; i < N - 1; i++) {
		for (j = N - 1; j > i; j--) {
			if (buffer[j] > buffer[j - 1]) {
				t = buffer[j];
				buffer[j] = buffer[j - 1];
				buffer[j - 1] = t;
			}

		}
	}
	for (i = 0; i < K; i++) {
		total += buffer[i];
	}
	printf("%d",total);
	free(buffer);
}

Measured memory_bytes: 128
def main():
    N, T = list(map(int, input().split(' ')))
    foods = [list(map(int, input().split(' '))) for _ in range(N)]
    # 食べ物は食べる時間の昇順に並べ替え、短い方を優先して食べるようにしておく。
    foods.sort(key=lambda food: food[0])
    # dp[n][t]: n個目までの食べ物のうち、時刻tまでに食べきる場合に得られるおいしさの合計の最大値。
    dp = [[0 for _ in range(T + 1)] for _ in range(N + 1)]
    for i, food in enumerate(foods):
        n = i + 1
        A, B = food
        for t in range(T + 1):
            val = dp[n - 1][t]
            if t - A >= 0 and dp[n - 1][t - A] + B > val:
                val = dp[n - 1][t - A] + B
            dp[n][t] = val
    # これを求める
    # max_n {dp[n - 1][T - 1] + (n個目の食べ物のおいしさ)}
    ans = 0
    for n in range(1, N + 1):
        v = dp[n - 1][T - 1] + foods[n - 1][1]
        ans = max(ans, v)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 149000
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			k = scanner.nextInt();
			d = scanner.nextInt();
			if ((m | n | k | d) == 0)
				break;
			int[] cake = new int[m];
			for (int i = 0; i < m; i++) {
				cake[i] = scanner.nextInt();
			}
			int N = m + n + 2;
			List<Pair>[] lists = new ArrayList[N];
			for (int i = 0; i < N; i++) {
				lists[i] = new ArrayList<Pair>();
			}
			while (d-- > 0) {
				int s = get(scanner.next());
				int t = get(scanner.next());
				int cost = scanner.nextInt() * k;
				lists[s].add(new Pair(t, cost));
				lists[t].add(new Pair(s, cost));
			}
			int[][] dist = new int[1 << m][N];
			for (int[] a : dist)
				Arrays.fill(a, 1 << 28);
			boolean[][] u = new boolean[1 << m][N];
			dist[0][n + m] = 0;
			u[0][n + m] = true;
			PriorityQueue<Pair> deque = new PriorityQueue<Pair>();
			deque.add(new Pair(n + m, 0, 0));
			while (!deque.isEmpty()) {
				Pair pair = deque.poll();
				int s = pair.first;
				int cost = pair.second;
				int bit = pair.bit;
				if(dist[bit][s]<cost)
					continue;
				for (Pair p : lists[s]) {
					if (m <= p.first) {
						int v = cost + p.second;
						if (v < dist[bit][p.first]) {
							dist[bit][p.first] = v;
							deque.offer(new Pair(p.first, v, bit));
						}
					} else {
						int aa = (bit >> p.first) & 1;
						if (aa == 1 )
							continue;
						int v = cost + p.second - cake[p.first];
						int newbit = bit | 1 << p.first;
						if (dist[newbit][p.first] > v) {
							dist[newbit][p.first] = v;
							deque.offer(new Pair(p.first, v, newbit));
						}
					}
				}
			}

			int min = 1 << 28;
			for (int j = 0; j < 1 << m; j++) {
				min = Math.min(min, dist[j][n + m + 1]);
			}
			System.out.println(min);
		}
	}

	private int get(String s) {
		if (s.charAt(0) == 'H')
			return n + m;
		if (s.charAt(0) == 'D')
			return n + m + 1;
		int x = Integer.parseInt(s.substring(1)) - 1;
		return s.charAt(0) == 'C' ? x : x + m;
	}

	int m, n, k, d;

	class Pair implements Comparable<Pair>{
		int first;
		int second;
		int bit;

		public Pair(int first, int second) {
			super();
			this.first = first;
			this.second = second;
		}

		public Pair(int first, int second, int bit) {
			super();
			this.first = first;
			this.second = second;
			this.bit = bit;
		}

		@Override
		public String toString() {
			return "Pair [first=" + first + ", second=" + second + ", bit="
					+ bit + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return this.second-o.second;
		}

	}
}

Measured memory_bytes: 69164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  int sum=0;
  rep(i,5){
    cin>>n;
    sum+=max(n,40);
  }
  cout<<sum/5<<endl;
}

Measured memory_bytes: 3088
n = int(input())

ans_sum = 0
max_num = 1
while True:
    if ans_sum + max_num >= n:
        break
    ans_sum += max_num
    max_num += 1

for i in range(1, max_num + 1)[::-1]:
    if i <= n:
        n = n - i
        print(i)

Measured memory_bytes: 3316
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi

if k==0
  putsend n**2
end
c1=(n-k+1)*(n-k)/2
c2=0
(k+1).upto(n) do |b|
  lastmod=n%b
  num = n-b+1
  eachnum = num/b
  diff=0
  if lastmod<k
    diff=0
  elsif lastmod==b-1
    diff=0
  else
    diff=lastmod-k+1
  end

  c2+=eachnum*(b-k)+diff
  #puts "b:#{b},#{c2}"
end

puts c1+c2

Measured memory_bytes: 1916
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort(reverse=True)

min_h = float('inf')
for i in range(N-K+1):
    temp = H[i] - H[i+K-1]
    min_h = min(min_h, temp)


print(min_h)

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

public class Main {


	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		boolean ans = true;
		if (n%3==0) {
			
			
			for (int i=0;i<n/3;i++) {
				if (a[i]!=a[0]) {
					ans = false;
				}
			}
			for (int i=n/3;i<n*2/3;i++) {
				if (a[i]!=a[n/3]) {
					ans = false;
				}
			}
			for (int i=n*2/3;i<n;i++) {
				if (a[i]!=a[n*2/3]) {
					ans = false;
				}
			}
			if ((a[0]^a[n/3]) != a[n*2/3]) {
				ans=false;
			}
						
		} else {
			
			for (int i=0;i<n;i++) {
				if(a[i]!=0) {
					ans=false;
				}
			}
		}
		System.out.println(ans ? "Yes" : "No");
	}


}

Measured memory_bytes: 49372
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u]=++tt;
  for(v=0 ; v<n ; v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0 ; u<n ; u++){
    color[u]=WHITE;
  }
  tt=0;

  for(u=0 ; u<n ; u++){
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(u=0 ; u<n ; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,k,v,i,j;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++) M[i][j]=0;
  }

  for(i=0 ; i<n ; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0 ; j<k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();

  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll N, d1, d2;
    cin >> N;
    ll num_suc = 0;
    bool is_ok = false;
    rep(i, N){
        cin >> d1 >> d2;
        if(d1 == d2){
            ++num_suc;
            if(num_suc>=3){
                is_ok = true;
            }
        }else{
            num_suc = 0;
        }
    }

    if(is_ok){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }

}

int main(){
    Main();
}

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

int main(){
  int64_t n,k,r,s,p;
  string T;
  cin >> n >> k >> r >> s >> p >> T;
  int64_t ans=0;
  string x="";
  for(int i=0;i<n;i++){
    if(T.at(i)=='r'){
      if(i>=k){
        if(x.at(i-k)!='p'){
          ans+=p;
          x+='p';
        }else{
          x+='a';
        }
      }else{
        ans+=p;
        x+='p';
      }
    }else if(T.at(i)=='p'){
      if(i>=k){
        if(x.at(i-k)!='s'){
          ans+=s;
          x+='s';
        }else{
          x+='a';
        }
      }else{
        ans+=s;
        x+='s';
      }
    }else if(T.at(i)=='s'){
      if(i>=k){
        if(x.at(i-k)!='r'){
          ans+=r;
          x+='r';
        }else{
          x+='a';
        }
      }else{
        ans+=r;
        x+='r';
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
struct Node
{
    int location;
    int p,l,r;
    Node(){l = r = p = -1;}
};
struct Point
{
    int id,x,y;
    Point(){}
    Point(int id,int x,int y): id(id),x(x),y(y){}
    bool operator<(const Point &p) const {
        return id < p.id;
    }
    void print(){
        printf("%d\n",id);
    }
};
const int MAX_N = 500000;
int N;
Point P[MAX_N * 2];
Node T[MAX_N * 2];
int np;
bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}
int build(int depth , int l,int r)
{
    if (l >= r)return -1;
    int mid= (l +r) >> 1;
    int t=np++;
    if (depth%2==0)
        sort(P+l,P+r,lessX);
    else
        sort(P+l,P+r,lessY);
    T[t].location=mid;
    T[t].l= build(depth + 1 , l,mid);
    T[t].r= build(depth + 1, mid+1,r);
    return t;
}
vector<Point> ans;
void find(int v,int sx,int tx,int sy,int ty,int depth){
    int x=P[T[v].location].x;
    int y=P[T[v].location].y;
    if (sx <=x && x<=tx && sy<=y && y<=ty)
        ans.push_back(P[T[v].location]);
    if (depth%2==0)
    {
        if(T[v].l!= -1)
            if (sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1);
        if(T[v].r!=- 1)
            if(x<=tx)find(T[v].r,sx,tx,sy,ty,depth+1);
    }
    else
    {
        if (T[v].l!=-1)
            if(sy<=y)find(T[v].l,sx,tx,sy,ty,depth+1);
        if(T[v].r!=-1)
            if (y<=ty)find(T[v].r,sx,tx,sy,ty,depth+1);
    }
}
int main()
{
    int x,y;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d %d",&x,&y);
        P[i]=Point(i,x,y);
    }
    np=0;
    int root= build(0 , 0 , N);
    int q;
    scanf("%d",&q);
    int sx,tx,sy,ty;
    for(int i=0;i<q;i++){
        scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
        ans.clear();
        find(root,sx,tx,sy,ty,0);
        sort(ans.begin(),ans.end());
        for(int j=0;j<ans.size();j++)
            ans[j].print();
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 23560
#include<stdio.h>


int main( void )
{
	while( 1 )
	{
		char AB[ 101 ] ;
		scanf( "%s" ,AB ) ;

		if( AB[ 0 ] == '0' )
		{
			return 0 ;
		}

		int a = 0 ;
		int b = 0 ;

		int i ;
		for( i = 1 ; AB[ i ] > 0 ; ++i )
		{
			a += 1 * ( AB[ i ] == 'A' ) ;
			b += 1 * ( AB[ i ] == 'B' ) ;
		}

		if( a > b )
		{
			++a ;
		}

		else
		{
			++b ;
		}

		printf( "%d %d\n" ,a ,b ) ;
	}

	return 0 ;
}


Measured memory_bytes: 2572
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
bool prime(int i){
  int num=0;
  for (int j=1;j<=i;j++)
    if (i % j == 0)
      num++;
  if (num==2) return true;
  return false;
}
int main(){
  int n,sum=0;
  cin>>n;
  for (int i=2;i<=55555;i++){
   	if (prime(i) && i % 5 == 1){sum++;
   	  if(sum<=n) cout<<i<<" ";
   	  else break;
   }
  }
  return 0;
}

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

int main(){
    string n;
    string w;
    int c, l, i;
    c = 0;
    
    cin >> w;
    
    while(true){
        cin >> n;
        if(n == "END_OF_TEXT") break;
        l = n.size();
        for(i = 0; i < l; i++){
            n[i] = tolower(n[i]);
        }
        if(n == w) c = c + 1;
    }
    
    cout << c << endl;
}



Measured memory_bytes: 3208
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	a,b,c=MI()
	ta,tb,tc=a,b,c
	ch = False
	cnt = 0
	while a%2==0 and b%2==0 and c%2==0:
		a,b,c=1/2*(b+c),1/2*(a+c),1/2*(b+a)
		if(a==ta and b==tb and c==tc):
			ch = True
			break
		cnt+=1
	if ch:
		print(-1)
	else:
		print(cnt)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
import sys

n = int(input())
s = input()

compare_check = 0
if (len(s) <= 1) or ((len(s)%2) == 1) :
  print("No")
  sys.exit()
else:
  for i in range(len(s)//2):
    if (s[i] == s[i+len(s)//2]):
      compare_check += 1

if ((len(s)//2) == compare_check) :
  print("Yes")
else:
  print("No")

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

template<class T> inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

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

    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    ll g = gcd(n, m);
    ll l = max(n, m) / g * min(n, m);

    ll ans = l;
    REP(i, g) {
        if (s[(i * n) / g] != t[(i * m) / g]) {
            ans = -1;
            break ;
        }
    }

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


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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
//#define x first
#define y second
#define point pair<int,int>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
int n,k;
vector<int> a;

int meme[2][110000];
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    cin>>n>>k;
    a = vector<int> (n);

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

    int mn = *min_element(a.begin(), a.end());
    for(int i = 0; i < mn; i++){
        meme[0][i] = 1;
        meme[1][i] = 0;
    }

    for(int i = mn; i <= k; i++){
        meme[0][i] = 1;
        meme[1][i] = 0;

        for(int j = 0; j < n; j++){
            if(i - a[j] < 0)
                continue;

            for(int turn = 0; turn < 2; turn++){
                if(meme[!turn][i - a[j]] == turn)
                    meme[turn][i] = turn;
            }
        }
    }

    cout<<((meme[0][k])? "Second":"First");
}


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

int main()
{
    vector<vector<int>> c(3, vector<int>(3));
    int sum = 0;
    for (auto i = 0; i < 3; i++)
    {
        for (auto j = 0; j < 3; j++)
        {
            int c_ij;
            cin >> c_ij;
            sum += c_ij;
            c[i][j] = c_ij;
        }
    }

    int mod_row_1 = (c[0][0] + c[0][1] + c[0][2]) % 3;
    int mod_row_2 = (c[1][0] + c[1][1] + c[1][2]) % 3;
    int mod_row_3 = (c[2][0] + c[2][1] + c[2][2]) % 3;
    int mod_col_1 = (c[0][0] + c[1][0] + c[2][0]) % 3;
    int mod_col_2 = (c[0][1] + c[1][1] + c[2][1]) % 3;
    int mod_col_3 = (c[0][2] + c[1][2] + c[2][2]) % 3;

    string ans = "No";

    if (ceil(float(sum) / 3) == floor(float(sum) / 3))
    {
        sum /= 3;
        if (mod_row_1 == mod_row_2 && mod_row_2 == mod_row_3)
        {
            if (mod_col_1 == mod_col_2 && mod_col_2 == mod_col_3)
            {
                if (sum % 3 == (mod_row_1 + mod_col_1) % 3)
                {
                    ans = "Yes";
                }
            }
        }
    }

    cout << ans << endl;
}

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

using ll = long long;
using ld = long double;
using point = std::complex<ld>;

constexpr ld eps = 1e-10;
const ld pi = std::acos(-1.0);

bool comp(point a, point b) {
    return std::real(a) < std::real(b) || (std::real(a) <= std::real(b) && std::imag(a) < std::imag(b));
}

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

int ccw(point a, point b, point c) {
    b -= a; c -= a;
    if(cross(b, c) > eps) return 1;
    if(cross(b, c) < -eps) return -1;
    if(dot(b, c) < 0) return 2;
    if(std::norm(b) < std::norm(c)) return -2;
    return 0;
}

ld triangle_area(point a, point b, point c) {
    return 0.5 * abs(cross(b - a, c - a));
}

vector<ld> calc_area(vector<point> const& ps, bool rev = false) {
    vector<ld> S(ps.size());
    vector<point> upper = {ps[0]}, lower = {ps[0]};
    for(int i = 1; i < (int)ps.size(); ++i) {
        S[i] = S[i - 1];
        while(upper.size() >= 2u && ccw(upper[upper.size() - 2], upper.back(), ps[i]) == 1) {
            S[i] -= triangle_area(upper[upper.size() - 2], upper.back(), lower.back());
            upper.pop_back();
        }
        while(lower.size() >= 2u && ccw(lower[lower.size() - 2], lower.back(), ps[i]) == -1) {
            S[i] -= triangle_area(lower[lower.size() - 2], lower.back(), upper.back());
            lower.pop_back();
        }
        S[i] += triangle_area(upper.back(), lower.back(), ps[i]);
        upper.push_back(ps[i]);
        lower.push_back(ps[i]);
    }
    if(rev) reverse(begin(S), end(S));
    return S;
}

int main() {
    int n; cin >> n;
    vector<point> ps, rps;
    for(int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        ps.emplace_back(x, y);
        rps.emplace_back(-x, y);
    }
    sort(begin(ps), end(ps), comp);
    sort(begin(rps), end(rps), comp);

    const auto lS = calc_area(ps), rS = calc_area(rps, true);
    ll ans = rS[0];
    for(int i = 0; i + 1 < n; ++i) {
        if(ps[i + 1].real() - ps[i].real() < eps) continue;
        ans = min(ans, (ll)roundl(lS[i] + rS[i + 1]));
    }

    cout << ans << endl;
}



Measured memory_bytes: 23824
N, Q = map(int, input().split())
S = input()

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])

Measured memory_bytes: 8436
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int cnt[20],v[N];
int dp[1<<20];
int dfs(int s)
{
	if(s==0) return 0;
	if(dp[s]!=-1) return dp[s];
	dp[s]=0x3f3f3f3f;
	for(int i=0;i<16;i++)
	{
		if(s>>i&1)
		{
			for(int j=0;j<16;j++)
			{
				if(s>>j&1)
				{
					int x=j^i;
					int ns=s^(1<<j)^(1<<i)^(1<<x);
					if(__builtin_popcount(ns)<__builtin_popcount(s))
					 dp[s]=min(dp[s],dfs(ns)+1+((s&(1<<x))==(1<<x)));
				}
			}
		}
	}
	return dp[s];
}
int main()
{
	int n;
	cin>>n;
	for(int i=1,x,y,z;i<n;i++)
	{
		cin>>x>>y>>z;
		v[x]^=z;
		v[y]^=z; 
	}
	memset(dp,-1,sizeof dp);
	for(int i=0;i<n;i++)
	 if(v[i]) cnt[v[i]]++;
	int ans=0,st=0;;
	for(int i=1;i<16;i++)
	{
		ans+=cnt[i]/2;
		st|=(cnt[i]&1)<<i;
	}
	ans+=dfs(st);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define int long
signed main(){
  int x;
  cin>>x;
  bool dp[100110]={0};
  dp[0]=true;
  for(int i=0;i<=x;++i){
    if(dp[i])for(int j=0;j<6;++j)dp[i+100+j]=true;
  }
  cout<<dp[x];
}

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

using namespace std;

int main(){
  string s;
  
  cin >> s;
  
  for(int i=0;i<s.size();i++){
    if(s[i] == '?'){
      s[i] = 'D';
    }
  }
  
  cout << s << endl;
}


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

int main() {
 
  string s;
  cin >> s;
  
  int change1 = 0;
  int change2 = 0;
  for(int i = 0; i < s.size(); i+=2) {
    if(s.at(i) == '0') {
      change1++;
    } else if(s.at(i) == '1') {
      change2++;
    }
    if(i+1 < s.size() && s.at(i+1) == '0') {
      change2++;
    } else if(i+1 < s.size() && s.at(i+1) == '1') {
      change1++;
    }
    //cout << change1 << change2 << endl;
  }
  
  int ans = 0;
  ans = min(change1, change2);
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  int n; cin >> n;
  map<int, int> l;

  auto prime_factorization_map = [&](int x) {
    for(int i = 2; i*i <= x; ++i) {
      int c = 0;
      while(x % i == 0) {
        ++c;
        x /= i;
      }
      if(c != 0) chmax(l[i], c);
    }
    if(x != 1) chmax(l[x], 1);
  };
  
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    prime_factorization_map(a[i]);
  }
  mint lcm = 1;
  for(auto x : l) {
    lcm *= modpow(x.first, x.second);
  }
  mint ans = 0;
  rep(i, n) ans += lcm/a[i];
  cout << ans.x << endl;
}

Measured memory_bytes: 768