akhauriyash/Code-Regression huggingface dataset:
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_3-B: Queue

#include <cstdio>

#define NDEBUG
#include <cassert>

template <typename T>
class Queue {
  unsigned int head_ = 0u;
  unsigned int size_ = 0u;
  const unsigned int max_;
  T* dp_;
public:
  Queue(unsigned int max) : max_(max) { dp_ = new T[max]; }
  ~Queue() { delete[] dp_; }
  void enqueue(T d)
  {
    assert(!is_full());
    const unsigned int tail = mod_by_max(head_+size_);
    dp_[tail] = d;
    ++size_;
  }

  T dequeue()
  {
    assert(!is_empty());
    T d = dp_[head_];
    head_ = mod_by_max(head_+1);
    --size_;
    return d;
  }

  inline bool is_empty() const { return size_ == 0; }
  inline bool is_full() const { return size_ == max_; }
private:
  inline int mod_by_max(unsigned int i) const { return i < max_ ? i : i -max_; }
};

struct Process {
  char name_[10+1];
  unsigned int time_;
  Process() = default;
  Process(const Process&) = delete;
  Process& operator=(const Process&) = delete;
  unsigned int exec(unsigned int quantum)
  {
    const unsigned int elapse = time_ > quantum ? quantum : time_;
    time_ -= elapse;
    return elapse;
  }
  bool is_finished() const { return time_ == 0; }
};

int main()
{
  unsigned int n, q;
  std::scanf("%d %d", &n, &q);

  Process processes[n];
  Queue<Process*> process_queue(n);
  for (auto i = 0U; i < n; ++i) {
    std::scanf("%10s %d", processes[i].name_, &processes[i].time_);
    process_queue.enqueue(&processes[i]);
  }

  const unsigned int quantum = q;
  unsigned int elapse = 0;
  while (!process_queue.is_empty()) {
    Process* current_process = process_queue.dequeue();
    elapse += current_process->exec(quantum);
    if (current_process->is_finished()) {
      printf("%s %d\n", current_process->name_, elapse);
    } else {
      process_queue.enqueue(current_process);
    }
  }
}

// eof

Measured memory_bytes: 3420
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>



int main(void) {

	int n, a, b,plana,planb;
	

	scanf("%d %d %d", &n, &a, &b);

	plana = n * a;
	planb = b;

	if (plana <= planb) {
		printf("%d", plana);
	}
	else {
		printf("%d", planb);
	}

	return 0;

}


Measured memory_bytes: 1736
#include <iostream>
using namespace std;
int main() {
	int N, P, evens = 0, odds = 0;
	cin >> N >> P;
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		if (x % 2 == 0) ++evens;
		else ++odds;
	}
	if (odds == 0) cout << (P == 0 ? (1LL << evens) : 0) << endl;
	else cout << (1LL << (evens + odds - 1)) << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func solve() {
	n := scanInt()
	var sum int64
	sum = 0
	var i int64
	for i = 0; i < int64(n+1); i++ {
		if i%3 != 0 && i%5 != 0 {
			sum += i
		}
	}
	fmt.Println(sum)
	return
}

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func pow(n int, m int) int {
	ans := 1
	for i := 0; i < m; i++ {
		ans *= n
	}
	return ans
}
func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 1760
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

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

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

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

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

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

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

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int H,W,A,B; cin>>H>>W>>A>>B;
  rep(i,H){
    rep(j,W){
      if(i<B){
        if(j<A) cout<<0;
        else cout<<1;
      }
      else{
        if(j<A) cout<<1;
        else cout<<0;
      }
    }
    cout<<endl;
  }
}













Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


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

	if (A + B >= 10) co("error");
	else co(A + B);

	Would you please return 0;
}

Measured memory_bytes: 256
object Main {
  def is_msprime(n: Int): Boolean = {
    if (n == 1 || (n % 7 != 1 && n % 7 != 6)) return false
    var x = 6
    var c = 0
    val y = List(2, 5)
    while(n >= x * x) {
      if (n % x == 0) return false
      x += y(c % 2)
      c += 1
    }
    true
  }

  def msprime_factorize(n: Int): List[Int] = {
    List(for (i <- 1 to math.sqrt(n).toInt if n % i == 0 && is_msprime(i)) yield i,
         for (i <- 1 to math.sqrt(n).toInt if n % i == 0 && i != n / i && is_msprime(n / i)) yield n / i).flatten
  }

  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt
    while(n != 1) {
      println(n + ": " + msprime_factorize(n).sorted.mkString(" "))
      n = sc.nextInt
    }
  }
}

Measured memory_bytes: 66028
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX_N=1e5;

signed main(){
    string S,T;cin>>S>>T;
    map<char,int>sm,tm;
    REP(i,S.size()){
        sm[S[i]]++;
        tm[T[i]]++;
    }
    vector<int>sv,tv;
    for(auto v:sm)sv.pb(v.second);
    for(auto v:tm)tv.pb(v.second);
    sort(sv.begin(),sv.end());
    sort(tv.begin(),tv.end());
    if(sv==tv)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 776
if __name__ == "__main__":
    S = input()
    T = input()
    N = len(S)
    M = len(T)
    ans = 10**9
    for i in range(N - M + 1):
        cnt = 0
        for j in range(M):
            if S[i + j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)
    print(ans)

Measured memory_bytes: 67608
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#include <math.h>
#include <bits/stdc++.h>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	int S,h,m,s;
	cin >> S;
	h = S/3600;
	m = (S-h*3600)/60;
	s = S-h*3600-m*60;
	cout << h << ":" << m << ":" << s << endl;
	
}



Measured memory_bytes: 3124
#include <iostream>
using namespace std;
int t = 1;
int d[100], f[100];
int a[100][100];
int N;
void dfs(int cur) {
 d[cur] = t;
 t++;
 for (int i=0; i<N; i++) {
  if (a[cur][i] == 1 && d[i] == 0) {
   dfs(i);
  }
 }
 f[cur] = t;
 t++;
}

int main() {
 cin >> N;
 for (int i=0; i<N; i++) {
  for (int j=0; j<N; j++) {
   a[i][j] = 0;
  }
  d[i] = 0;
  f[i] = 0;
 }
 for (int i=0; i<N; i++) {
  int u, k;
  cin >> u >> k;
  for (int j=0; j<k; j++) {
   int v;
   cin >> v;
   a[u-1][v-1] = 1;
  }
 }
 for (int i=0; i<N; i++) {
  if (d[i] == 0) { dfs(i); }
 }
 for (int i=0; i<N; i++) {
  cout << i+1 << " " << d[i] << " " << f[i] << endl;
 }
}


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

using namespace std ; 

int n; 

vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ; 


int main(){
    //freopen("in.in" , "r" , stdin ) ; 
    cin>>n; ;
    cout<<a[n-1] ; 
    return 0 ; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    for (int i =0; i< k;i++) {
        if (a >= b) {
            b *=2;
            continue;
        } 
        if (b >= c) {
            c*=2;
            continue;
        }
    }
    if (b > a && c > b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n, m, k ;
    cin >> n >> m >> k ;
    vll a(n) ;
    vll b(m) ;
    REP(i,n){
        cin >> a[i] ;
    }
    REP(i,m){
        cin >> b[i] ;
    }
    vll suma(n) ;
    vll sumb(m) ;
    ll ans = 0 ;
    suma[0] = a[0] ;
    sumb[0] = b[0] ;
    REP(i,n-1){
        suma[i+1] = suma[i] + a[i+1] ;
    }
    REP(i,m-1){
        sumb[i+1] = sumb[i] + b[i+1] ;
    }
    REP(i,m){
        if(sumb[i]<=k){
            ans = i+1 ;
        }
    }
    REP(i,n){
        if(suma[i]>k){
            break ;
        }
        ll tmp = i+1 ;
        auto it = UB(ALL(sumb),k-suma[i]) ;
        tmp += (ll)(it - sumb.begin()) ;
        ans = max(ans,tmp) ;
    }
    cout << ans <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 9524
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int gcd(int a, int b){
    if(!b) return a;
    return gcd(b, a%b);
}
int main (){
    int N, K; cin >> N >> K;
    vector<int> world(N);
    int mx = 0;
    for(int &a:world){
        cin >> a;
        mx = max(mx, a);
    }
    if(mx < K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int hello = world[0];
    for(int i=1; i<N; i++){
        hello = gcd(hello, world[i]);
    }
    for(int i=0; i<N; i++){
        if(abs(world[i]-K)%hello==0){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 640
n = int(input())
t = []
sum = 0
for _ in range(n):
    s = int(input())
    sum += s
    t.append(s)
t.sort()
ans = sum
if sum % 10 == 0:
    for i in t:
        sum -= i
        if sum % 10 != 0:
            ans = sum
            break
        else:
            sum += i
    if sum % 10 == 0:
        ans = 0
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


signed main(){
    int N;
    scanf("%lld",&N);
    int ans=0;
    for(int i=1;i<=N;i+=2){
        int count=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)count++;
        }
        if(count==8)ans++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
# your code goes here
def my_index(l, x, default=False):
    if x in l:
        return int(l.index(x))+1
    else:
        return default

ans = []

num = int(input())

for i in range(1,50001):
    ans.append(int(i*1.08))

print(my_index(ans,num,":("))


Measured memory_bytes: 10956
#include <stdio.h>
#include <algorithm>

constexpr int N = 2e3;
int L[N];

// abs(a-b) < c < a+b

int main(void){
    int n; scanf("%d", &n);
    int i, j, k, l;
    for(i = 0; i < n; ++i) scanf("%d", L+i);
    long long int res = 0;
    std::sort(L, L+n);
    for(i = 0; i < n; ++i){
        for(j = i + 1; j < n; ++j){
            l = L[i] + L[j];
            for(k = j + 1; k < n; ++k){
                if(L[k] < l) res++;
                else break;
            }
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n; cin>>n;
	ll f[n][10], p[n][11], x;
	for (int i=0; i<n; ++i) for(int j=0; j<10; ++j) cin>>f[i][j];
	for (int i=0; i<n; ++i) for (int j=0; j<=10; ++j) cin>>p[i][j];
	ll ans=-100000000000000;
	for (int i=1; i<(1<<10); ++i){
		vector<int> cur(n, 0);
		x=0;
		for (int j = 0; j<10; ++j) if (i&(1<<j)){
			for (int k=0; k<n; ++k) if(f[k][j]) cur[k]++;
		}
		for (int j=0; j<n; ++j) x+=p[j][cur[j]];
		ans= max(ans, x);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head &&head, Tail &&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, a, b, k);

  auto f = [](int &a, int &b) {
    if (a % 2 == 1) a--;
    b += a / 2;
    a /= 2;
  };

  for (int i = 0; i < k; ++i) {
    if (i % 2 == 0)
      f(a, b);
    else
      f(b, a);
  }

  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
use strict;
use warnings;

chomp(my $n = <>);
my @job = ();
foreach (1 .. $n) {
	my ($a, $b) = split /\s/, <>;
	push @job, [$a, $b];
}

@job = sort {$a->[1] <=> $b->[1]} @job;

my $tim = 0;
my $ans = 'Yes';
foreach my $j (@job) {
	my ($a, $b) = ($j->[0], $j->[1]);
	
	$tim += $a;
	if ($tim > $b) {
		$ans = 'No';
		last;
	}
}

print $ans, "\n";



Measured memory_bytes: 62592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
using VI = vector<int>;

constexpr ll INF = 1000000007;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int cnt = 1;
    while (true) {
        if (a <= 0) {
            cout << "No\n";
            return 0;
        }
        else if (c <= 0) {
            cout << "Yes\n";
            return 0;
        }

        if (cnt % 2 == 1) {
            c -= b;
        }
        else {
            a -= d;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#define rep(i, l, n) for(int i = l; i < n; i++)

using namespace std;
typedef long long ll;

int main () {
    int i, j, n; cin >> n;
    ll min, max, R;
    cin >> min >> R;
    max = R - min;
    if (min > R) min = R;
    rep(i, 1, n-1) {
        cin >> R;
        if (max < R - min) max = R - min;
        if (min > R) min = R;
        //printf("max %lld min %lld\n", max, min);
    }
    printf("%lld\n", max);
    return 0;
}


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

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int N;
    cin >> N;
    bool f = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (a & 1) {
            f = 1;
            break;
        }
    }
    if (f) {
        puts("first");
    } else {
        puts("second");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
ll gcd(ll a,ll b){
    if(!b)
        return a;
    return gcd(b,a%b);
}
int main()
{
    fast();
    ll n,m;
    cin>>n>>m;
    set<ll>s;
    for(ll i=1;i*i<=m;i++){
        if(m%i==0){
            s.insert(i);
            s.insert(m/i);
        }
    }
    ll res=1;
    for(auto &i:s){
        if(m/i>=n)
            res=i;
    }
    cout<<res;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int dis1 = Math.abs(x-a);
        int dis2 = Math.abs(x-b);
        if(dis1 < dis2){
            System.out.println("A");
        }else{
            System.out.println("B");
        }
    }
}

Measured memory_bytes: 22996
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define com bool operator<(const node &b)const
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
int a[maxn];

void solve() {
    int n;
    cin >> n;
    int sum = 0;
    rep(i, 1, n)cin >> a[i];
    int maxx = a[1];
    rep(i, 2, n) {
        if (maxx < a[i])
            maxx = a[i];
        else
            sum += maxx - a[i];
    }
    cout << sum;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 5220
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok cout<<"ok"<<endl
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back
using namespace std;
int main()
{
	int a,b;
	char sin[6]={'A','B','C','D','E','F'};
    char c1,c2;
    cin >> c1;
    cin >> c2;
	rep(i,6)
	{
		if(sin[i]==c1)
			a=i;
		if(sin[i]==c2)
			b=i;
	}
    if(a<b)
        cout<<"<";
    else if(a>b)
        cout<<">";
	else
		cout<<"=";

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

int x, y, z, k;
int a[1010], b[1010], c[1010];
int d[1000010], e[3000000];
signed main() {
	scanf("%lld %lld %lld %lld", &x, &y, &z, &k);
	rep(i, x) {
		scanf("%lld", &a[i]);
	}
	rep(i, y) {
		scanf("%lld", &b[i]);
	}
	rep(i, z) {
		scanf("%lld", &c[i]);
	}
	rep(i, x) {
		rep(j, y) {
			d[i * y + j] = a[i] + b[j];
		}
	}
	sort(d, d + x * y, greater<int>());
	rep(i, k) {
		rep(j, z) {
			e[i * z + j] = d[i] + c[j];
		}
	}
	sort(e, e + k * z, greater<int>());
	rep(i, k) {
		printf("%lld\n", e[i]);
	}
}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

vector<int> a;

int main() {
	int n;
	cin >> n;
	FOR (i, n) {
		int b;
		cin >> b;
		a.pb(b);
	}
	LL cnt = 0;
	a.pb(0);
	FOR (v, n) {
		int b = a[v] / 2;
		cnt += b;
		a[v] -= 2 * b;
		b = min(a[v], a[v + 1]);
		cnt += b;
		a[v + 1] -= b;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 892
a = input().split()
N=int(a[0])
M=int(a[1])
ans=[-1]*N
for i in range(M):
  s,c = map(int, input().split())
  if s==1 and c==0 and N!=1:
    print(-1)
    exit()
    break
  elif ans[s-1]==-1:
    ans[s-1]=c
  elif ans[s-1]==c:
    pass
  elif ans[s-1]!=c and ans[s-1]!=-1:
    print(-1)
    exit()
    break
else:
  if ans[0]==-1:
    ans[0]=1 if N!=1 else 0
  for j in range(1,N):
    if ans[j]==-1:
      ans[j]=0
res=map(str,ans)
res=''.join(res)
print(int(res))

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long h , w , n ;
long long cnt[10] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>h>>w>>n ;
	set< pair<int , int> >s ;
	set< pair<int , int> >mark ;
	while(n--)
	{
		int x , y ;
		cin>>x>>y ;
		mark.insert({x , y}) ;
		for(int i = max(1 , x-2) ; i <= min(x*1ll , h-2ll) ; ++i)
		{
			for(int j = max(1 , y-2) ; j <= min(y*1ll , w-2ll) ;  ++j)
				s.insert({i , j}) ;
		}
	}
	for(auto &p : s)
	{
		int x = p.first , y = p.second ;
		int cnt2 = 0 ;
		for(int i = x ; i <= min(h , x+2ll) ; ++i)
		{
			for(int j = y ; j <= min(w , y+2ll) ; ++j)
			{
				if(mark.find({i , j}) != mark.end())
					cnt2++ ;
			}
		}
		cnt[cnt2]++ ;
	}
	long long ans = (h-2ll)*(w-2ll)-s.size() ;
	cout<<ans<<"\n" ;
	for(int i = 1 ; i <= 9 ; ++i)
		cout<<cnt[i]<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 47104
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "Impossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()

int main(){
  
  lint n, m; cin >> n >> m;
  vector<lint> x(n);
  vector<lint> y(m);
  rep(i, n) cin >> x[i];
  rep(i, m) cin >> y[i];
  
  sort(all(x));
  sort(all(y));

  lint ansx = 0;
  lint ansy = 0;

  rep(i, n){
    ansx += x[i] * i;
    ansx -= x[i] * (n - i - 1);
    ansx = (ansx + MOD) % MOD;
  }

  rep(i, m){
    ansy += y[i] * i;
    ansy -= y[i] * (m - i - 1);
    ansy = (ansy + MOD) % MOD;
  }
  
  cout << ansx * ansy % MOD << endl;

  return 0;
}


Measured memory_bytes: 1792
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

let collatz s =
    let f n = if n % 2 = 0 then n / 2 else 3 * n + 1
    seq {
        yield s
        yield! Seq.unfold (fun x -> Some (f x, f x)) s
    }

let solve s =
    let mutable memo = Set.empty
    seq {
        for (i, x) in Seq.zip (Seq.initInfinite ((+) 1)) (collatz s) do
            if Set.contains x memo
            then yield i
            else memo <- Set.add x memo
    }
    |> Seq.head

[<EntryPoint>]
let main argv =
    let s = read int
    printfn "%i" (solve s)
    0

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string ss,tt;cin>>ss>>tt;
  ss+=tt;
  int r=stoi(ss);
  for(int i=1;i*i<=100100;i++){
      if(i*i==r){
          cout<<"Yes"<<endl;
          return 0;
      }
  }
  cout<<"No"<<endl;
  return 0;
  }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
 
namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = ReadLong();
            var ans = (x / 11) * 2;
            var a = x % 11;
            if (a == 0)
            {
                
            }
            else if (a <= 6)
            {
                ans += 1;
            }
            else
            {
                ans += 2;
            }
 
            WriteLine(ans);
        }
       
 
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
 
        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }
 
        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }
 
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<iomanip>
#define loop(i,start,end) for(int i=start;i<end;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    double pi=3.1415926;
    double area=(double)n*2*pi;
    cout<<fixed<<setprecision(20)<<area;
}


Measured memory_bytes: 3804
S = list(input())
N = len(S)
flag = 0
for i in range(1,N):
    if i==1:
        if S[i]==S[i-1]:
            flag = 1
            print(i-1+1,i+1)
            break
    else:
        if S[i]==S[i-1]:
            flag = 1
            print(i-1+1,i+1)
            break
        if S[i]==S[i-2]:
            flag = 1
            print(i-2+1,i+1)
            break

if flag==0:
    print(-1,-1)

Measured memory_bytes: 49520
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,an=99999999999999999;
	cin >> N;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			an = min(an, i + (N / i) - 2);
		}
	}
	cout << an << endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i 
v = gets.chomp.split().map(&:to_i)
c = gets.chomp.split().map(&:to_i)
b = []
ans = 0

N.times do |n|
  b[n] = v[n] - c[n]
end

b.sort!
N.times do |n|
  if b[n] > 0
    ans += b[n]
  end
end

p ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
	// your code goes here
	int a[10];
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a,a+10);
	cout<<a[9]<<endl;
	cout<<a[8]<<endl;
	cout<<a[7]<<endl;
	return 0;
}

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

ll gcd(ll a,ll b){
  return b ? gcd(b,a%b) : a;
}


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  ll ans=a[0];
  for(int i=1;i<n;++i){
    ans=ans*a[i]/gcd(ans,a[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3100
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


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


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


n, a = inpm(2)
print(n**2-a)


Measured memory_bytes: 3572
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n, k;
    cin >> n >> k;

    vector<int> x(n);

    rep(i, n) {
        cin >> x[i];
    }

    int ans;
    rep(i, n) {
        ans += min(x[i], abs(x[i]-k));
    }

    cout << ans*2;

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  // 2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



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

int main(){
    size_t K;
    cin >> K;
    vector<unsigned long> A(K);
    copy_n(istream_iterator<unsigned long>(cin), K, A.rbegin());
    unsigned long R{2}, L{2};
    for(const auto& i : A){
        auto r{(R + i - 1) / i}, l{L / i};
        if(r > l)return 0 & puts("-1");
        R = r * i;
        L = (l + 1) * i - 1;
    }
    cout << R << " " << L << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
//#define f first
//#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>
 
using namespace std;
 
const int maxn = 132675;
const int INF = (int)1e9;
 
ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;
 
ll x[maxn],y[maxn],x2[maxn],y2[maxn];
 
bool u[maxn], m, f;
 
vector <int> v;
 /*
void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}
*/ 
ll ans;
 
ll pref;
 
//vector <int> g[maxn],d[maxn];
 
ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/

map <int, int> col; 
 
char ch;

string s; 

int main()
{
	cin >> s;
	for(int i = s.size() - 2; i >= 0; --i){
		if(s[i] != s[i + 1]){
			cnt++;
			s[i + 1] = s[i];
			//f = 1;
		}
		else if(s[i] == s[i + 1]){
			s[i + 1] = s[i];
		}
	}
	//cout << s;
	cout << cnt;
	gg
}

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

const int maxn = 1e5+5;
int N, a[maxn];
int K;
int dp[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> a[i];
    for (int i = N - 1; i >= 1; i--) {
        dp[i] = 2e9+9;
        for (int j = i + 1; j <= min(N,i+K); j++) {
            dp[i] = min(dp[i],dp[j] + abs(a[i]-a[j]));
        }
    }
    cout << dp[1] << '\n';


    return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    
}
bool vis[200005];
int v[200005],ans[200005];
vector<int> a[200005];
void dfs(int x,int to_add){
    vis[x]=true;
    ans[x]+=to_add;
    for(auto it:a[x]){
        if(!vis[it]){
            dfs(it,to_add+v[it]);
        }
    }
}
int main() {
    io();
    int n,q,x,y,i,j,k;
    cin>>n>>q;
    for(i=0;i<n-1;i++){
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    while(q--){
        int val,id;
        cin>>id>>val;
        v[id]+=val;
    }
    dfs(1,v[1]);
    for(i=1;i<=n;i++)   cout<<ans[i]<<' ';
}





Measured memory_bytes: 19456
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2e5+9;
int n;
ll a[sz];
ll k;

bool ok(ll x){
	ll ret=0;
	for(int i=0;i<n;i++){
		int pos;
		if(!a[i]) ret+=(x>=0?n-1:0);
		else if(a[i]>0){
			// y*a[i]<=x
			// y<=x/a[i];
			ll y=x/a[i];
			if(x%a[i]){
				if(x<0) y--;
			}
			pos=upper_bound(a,a+n,y)-a;
			if(pos<=n-1) ret+=pos-(pos-1>=i);
			else ret+=n-1;
		}else{
			// y*a[i]<=x
			// y>=x/a[i]
			ll y=x/a[i];
			if(x%a[i]){
				if(x<0) y++;
			}
			pos=lower_bound(a,a+n,y)-a;
			if(pos<=n-1) ret+=n-pos-(pos<=i);
		}
	}
	ret>>=1;
	return ret>=k;
}


int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	ll st=-1e18,en=1e18;
	while(st<en){
		ll mid=(st+en)>>1;
		if(ok(mid)) en=mid;
		else st=mid+1;
	}
	cout<<st;
	return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int A =scan.nextInt();
		int B =scan.nextInt();
		if(A==1){
			A=14;
		}
		if(B==1){
			B=14;
		}
		if(A>B){
			System.out.println("Alice");
		}else if(B>A){
			System.out.println("Bob");
		}else{
			System.out.println("Draw");
		}

		}
		
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}

typedef pair <int, int> pii;
#define fi first
#define se second

const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
pii mi[21][maxn << 1];
int n, m;
int lg[maxn], val[maxn], ans[maxn];

struct node{ int v, l, r, x, y;
  bool operator < (const node &b) const {
	return v < b.v; 
  }
};

priority_queue <node> q;

pii query(int l, int r){
  int t = lg[r - l + 1];
  return min(mi[t][l], mi[t][r - (1 << t) + 1]);
}

void push(int l, int r){
  if(l > r) return ;
  pii x = query(l, r);
  pii y = query(x.se + 1, r + 1);
  q.push((node){-x.fi, l, r, x.se, y.se});
}

int main(){
  rd(n);
  rep(i, 1, n) rd(val[i]), mi[1][i] = pii(val[i], i);
  rep(i, 2, n) lg[i] = lg[i >> 1] + 1;
  rep(i, 2, lg[n]) rep(j, 1, n)
	mi[i][j] = min(mi[i - 1][j], mi[i - 1][j + (1 << i - 1)]);
  push(1, n);
  while(!q.empty()){
	node t = q.top(); q.pop();
	ans[++ m] = val[t.x];
	ans[++ m] = val[t.y];
	push(t.l, t.x - 1);
	push(t.x + 1, t.y - 1);
	push(t.y + 1, t.r);
  }
  rep(i, 1, m) printf("%d ", ans[i]);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int k = 0;
  rep(i,n) if (p[i] != i+1) k++;
  if (k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int x[10000];
	int count = 0;
	while(1)
	{
		cin >> x[count];
		if (x[count] == 0)
			break;
		count++;
	}

	for (int i = 0; i < count; ++i)
		cout << "Case " << i + 1 << ": " << x[i] << endl;

}




Measured memory_bytes: 3044
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  s = input()
  count_01 = 0
  count_10 = 0
  n = len(s)
  for i in range(n):
    if i%2==0:
      if s[i] == '0':
        count_01 += 1
      else:
        count_10 +=1
    else:
      if s[i] == '1':
        count_01 += 1
      else:
        count_10 += 1
  print(min(n-count_01,n-count_10))
        
  
  
if __name__ == '__main__':
  main()

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

int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1],cnt=0,sum=0;
	float k;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
		
	k=sum*1.0/(4.0*m);
	for(int i=1;i<=n;i++)
		if(a[i]>=k)
			cnt++;
	
	if(cnt>=m) cout<<"Yes"<<endl;
	else        cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    std::string s;
    cin >> s;
    if((s[0]!=s[1])||(s[0]!=s[2])||(s[1]!=s[2])){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256